-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
2845 lines (2715 loc) · 158 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import discord
from discord.ui import Button, View
from discord.ext import commands
import asyncio
import os
from io import StringIO
from time import time
import datetime
from random import sample as choices
import redis
db = redis.Redis(host=os.environ['REDISHOST'], port=os.environ['REDISPORT'], password=os.environ['REDISPASSWORD'])
default_prefix = '!'
intents = discord.Intents().all()
intents.presences = False
client = commands.Bot(command_prefix=default_prefix, intents=intents)
## HELP ##
helplist = {"help":["Help","Shows the help page","help"],
"role":["Role","Gives/Removes a role from member","role <user> <role>"],
"warn":["Warn","Warns a member","warn <user> [reason]"],
"warns":["Warns","Shows all the warns for a member","warns <user>"],
"clearwarn":["Clearwarn","Clear a warn/all warns for a member","clearwarn <user> [Warn-ID]"],
"punishments":["Punishments","Shows all the punishment for a member","punishments <user>"],
"clearpunishment":["Clearpunishment","Clear a punishment/all punishments for a member","clearpunishment <user> [Punishment-ID]"],
"purge":["Purge","Deletes the number of messages given from the channel","purge <all | no. of messages>"],
"timeout":["Timeout","Times out a member for given time from the guild","timeout <user> <time> [reason]"],
"removetimeout":["Removetimeout","Removes timeout from a member from the guild","removetimeout <user>"],
"mute":["Mute","Mutes member for given time from the guild","mute <user> [time] [reason]"],
"unmute":["Unmute","Unmutes a member from the guild","unmute <user>"],
"kick":["Kick","Kicks a member from the guild","kick <user> [reason]"],
"ban":["Ban","Bans a member from the guild","ban <user> [time] [reason]"],
"softban":["Softban","Bans a member from the guild without deleting any messages","softban <user> [time] [reason]"],
"hardban":["Hardban","Bans a member from the guild and deletes there messages from past 7 days","hardban <user> [time] [reason]"],
"unban":["Unban","Unbans a member from the guild","unban <user>"],
"avatar":["Avatar","Shows the avatar of a user","avatar [user]"],
"membercount":["Membercount","Shows the member count of the guild","membercount"],
"note":["Note","Adds a note to the user","note <user> <note>"],
"notes":["Notes","Shows the notes for the user","notes <user>"],
"clearnote":["Clearnote","Clears a note/all notes from the user","clearnote <user> <Note-ID>"],
"gstart":["Gstart","Starts a giveaway in the current channel","gstart <time> <winners> <prize>"],
"gcreate":["Gcreate","Creates a giveaway (Beginner Friendly Command)","gcreate"],
"gend":["Gend","Ends a giveaway","gend <Message-ID>"],
"greroll":["Greroll","Rerolls a giveaway","greroll <Message-ID>"],
"welcome":["Welcome","Sets the welcome channel and message","welcome [channel] [message]"],
"goodbye":["Goodbye","Sets the goodbye channel and message","goodbye [channel] [message]"],
"logs":["Logs","Sets the logs channel","logs [channel]"],
"invitelogs":["Logs","Sets the invite logs channel","invitelogs [channel]"],
"autorole":["Autorole","Gives the role to the member on joining","autorole <role>"],
"counting":["Counting","Sets the counting channel","counting [channel]"],
"resetcount":["Resetcount","Sets the counting to 0","resetcount"],
"setcount":["Setcount","Changes the counting to the count given","setcount <count>"],
"count":["Count","Returns the current count","count"],
"lock":["Lock","Locks the mentioned channel","lock [all/channel]"],
"unlock":["Unlock","Unlocks the mentioned channel","unlock [all/channel]"],
"afk":["Afk","Sets your Afk","afk [reason]"],
"invitelinks":["Invitelinks","Sets up the invitelinks deletion channels","invitelinks <disable/enable> [all/channel]"],
"links":["Links","Sets up the links deletion channels","links <disable/enable> [all/channel]"],
"leveling":["Leveling","Sets up the leveling channels","leveling <enable/disable> [all/channel]"],
"announce":["Announce","Announces the message given","announce [channel] <message>"],
"embed":["Embed","Sends an Embed with given color and message","embed [channel] <color> <title|description|footer>"],
"setprefix":["Setprefix","Changes the prefix for the guild","setprefix <new-prefix>"],
"botinfo":["Botinfo","Displays the details of the bot","botinfo"],
"rr":["Rr","Creates a reation role in the mentioned channel with the given title","rr <channel> <title>"],
"setlevel":["Setlevel","Changes the level and xp of a member","setlevel <member> <level>"],
"resetlevels":["Resetlevels","Resets everyone's levels in the guild","resetlevels"],
"rank":["Rank","Shows the rank and level of a member","rank [member]"],
"invites":["Invites","Shows the invites of a member","invites [member]"],
"addinvites":["Addinvites","Adds invites to a member","addinvites <member> <count>"],
"removeinvites":["Removeinvites","Removes invites from a member","removeinvites <member> <count>"],
"resetinvites":["Resetinvites","Resets everyone's invites in the guild","resetinvites"],
"messages":["Messages","Shows the message count of a member","messages [member]"],
"addmessages":["Addmessages","Adds the message count given to a member","addmessages <member> <count>"],
"removemessages":["Removemessages","Removes the message count given from a member","removemessages <member> <count>"],
"resetmessages":["Resetmessages","Resets everyone's message count in the guild","resetmessages"],
"leaderboard":["Leaderboard","Shows the ranking leaderboard of the guild","leaderboard [rank/messages/invites]"],
"bug":["Bug","Sends the bug reported in the bot support server","bug <bug>"],
"invite":["Invite","Sends the invite link of SmartBot","invite"],
"vote":["Vote","Sends the voting link of SmartBot","vote"],
"votes":["Votes","Shows the number of votes for a user","votes [user]"],
"topvotes":["Topvotes","Shows the voting leaderboard for SmartBot","topvotes"],
"userinfo":["Userinfo","Shows information about a member","userinfo [member]"],
"serverinfo":["Serverinfo","Shows information about the server","serverinfo"],
"roleinfo":["Roleinfo","Shows information about a role","roleinfo <role>"],
"ping":["Ping","Replies with Pong!","ping"],
"addlevelreward":["Addlevelreward","Adds a level reward/role for the guild","addlevelreward <level> <role>"],
"removelevelreward":["Removelevelreward","Removes a level reward/role for the guild","removelevelreward <level>"],
"levelrewards":["Levelrewards","Shows the level rewards/roles for the guild","levelrewards"],
"addcommand":["Addcommand","Adds a custom command for the guild","addcommand <command> <output>"],
"removecommand":["Removecommand","Removes a custom command for the guild","removecommand <command>"],
"commands":["Commands","Shows the custom commands for the guild","commands"],
"suggest":["Suggest","Sends a suggestion for the guild","suggest <suggestion>"],
"setsuggest":["Setsuggest","Sets the suggestion channel for the guild","setsuggest [channel]"],
"setsuggestlogs":["Setsuggestlogs","Sets the suggestion logs channel for the guild","setsuggestlogs [channel]"],
"accept":["Accept","Accepts a suggestion","accept <Message-ID> [Reply]"],
"deny":["Deny","Denies a suggestion","deny <Message-ID> [Reply]"],
"nick":["Nick","Changes the member's nickname","nick [member] <name>"],
"poll": ["Poll", "Starts a poll (max 10 choices)", "poll \"<message>\" \"<choice1>\" \"<choice2>\" ... \"[choice10]\""],
"steal": ["Steal", "Adds/Steals the emoji from another server", "steal <emoji>"]}
client.remove_command("help")
@client.command()
async def help(ctx, command=None):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
if command==None:
em = discord.Embed(title="Smart Bot's Help Page", description=f"Use {prefix}help <command> for extended information on a command", color=3447003)
em.add_field(name=":pick: Configuration", value="`setprefix`, `welcome`, `goodbye`, `logs`, `autorole`, `counting`, `setcount`, `resetcount`, `links`, `invitelinks`", inline=False)
em.add_field(name=":hammer: Management", value="`rr`, `steal`, `announce`, `embed`, `role`, `purge`, `note`, `notes`, `clearnote`, `lock`, `unlock`", inline=False)
em.add_field(name=":hammer_pick: Moderation", value="`warn`, `warns`, `clearwarn`, `punishments`, `clearpunishment`, `timeout`, `removetimeout`, `mute`, `unmute`, `kick`, `ban`, `softban`, `hardban`, `unban`", inline=False)
em.add_field(name=":tools: Utility", value="`poll`, `nick`, `serverinfo`, `userinfo`, `roleinfo`, `afk`, `avatar`, `membercount`, `count`", inline=False)
em.add_field(name=":bar_chart: Leveling & Invites", value="""`rank`, `leaderboard`, `leveling`, `setlevel`, `addlevelreward`, `removelevelreward`, `levelrewards`
`invites`, `leaderboard invites`, `invitelogs`, `addinvites`, `removeinvites`,
`messages`, `leaderboard messages`, `addmessages`, `removemessages`""", inline=False)
em.add_field(name=":tada: Giveaways", value="`gcreate`, `gstart`, `gend`, `greroll`", inline=False)
em.add_field(name=":bulb: Suggestions", value="`suggest`, `setsuggest`, `setsuggestlogs`, `accept`, `deny`", inline=False)
em.add_field(name=":name_badge: Custom commands", value="`addcommand`, `removecommand`, `commands`", inline=False)
em.add_field(name=":pushpin: Help & Support", value="`help`, `invite`, `vote`, `votes`, `topvotes`, `botinfo`, `ping`, `bug`", inline=False)
await ctx.reply(embed=em)
elif command in helplist:
em = discord.Embed(title=helplist[command][0], description=helplist[command][1], color=3447003)
em.add_field(name="**Syntax**", value=prefix+helplist[command][2])
await ctx.reply(embed=em)
else:
await ctx.reply(f"<a:no:923454180427980821> Command **'{command}'** not found")
@client.command()
async def invite(ctx):
em = discord.Embed(color=3447003)
em.add_field(name="__SmartBot ✨__", value="[Invite link (recommended)](https://discord.com/api/oauth2/authorize?client_id=810526674025316412&permissions=1644906413303&scope=bot)\n[Invite link (admin)](https://discord.com/api/oauth2/authorize?client_id=810526674025316412&permissions=8&scope=bot)", inline=False)
em.add_field(name="__Support Server__", value="[SmartBot ✨ Support Server](https://discord.gg/7gPzprfT)", inline=False)
em.set_author(name="➤ Invite Links", icon_url="https://cdn.discordapp.com/avatars/810526674025316412/01feb2f2199004dfc9d83bb187fdb77a.png")
em.set_thumbnail(url="https://cdn.discordapp.com/icons/917850586358104064/98726b1bceb8b66243b8e25f553fdee5.png")
btn1 = Button(label="Invite",emoji="🔗", url="https://discord.com/api/oauth2/authorize?client_id=810526674025316412&permissions=8&scope=bot")
btn2 = Button(label="Support",emoji="❔", url="https://discord.gg/7gPzprfT")
view = View()
view.add_item(btn1)
view.add_item(btn2)
await ctx.reply(embed=em, view=view)
@client.command()
@commands.has_permissions(manage_guild=True)
async def setprefix(ctx, prefix):
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
settings[ctx.guild.id]['prefix'] = prefix
db.set('settings', str(settings))
await ctx.reply(f"<a:yes:923454161666863174> Changed the server prefix to {prefix}")
@setprefix.error
async def setprefix_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
async def botinfo(ctx):
guilds = "{:,}".format(len(client.guilds))
channels = "{:,}".format(sum(len(guild.channels) for guild in client.guilds))
members = "{:,}".format(len(client.users))
latency = round(client.latency * 1000)
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
e = discord.Embed(title="SmartBot ✨", description=f"""```🏘️ Servers : {guilds}
👤 Users : {members}
📑 Channels : {channels}
🔴 Ping : {latency}
⚙️ Prefix : {prefix}```""")
e.set_footer(text="Created by Toofan#4848")
await ctx.reply(embed=e)
## BOT MODERATORS ##
@client.command()
async def guilds(ctx, count: int=None):
if ctx.channel.id != 931072761856655371: return
if count==None:
data = ""
x=1
for guild in client.guilds:
data += f"{x}) {guild.id} : {str(guild.owner)} : {sum(not member.bot for member in guild.members)}\n"
if x%50==0:
e = discord.Embed(description = data)
await ctx.send(embed=e)
data = ""
x+=1
e = discord.Embed(description = data)
await ctx.send(embed=e)
else:
data = ""
x=1
for guild in client.guilds:
if sum(not member.bot for member in guild.members)==count:
data += f"{x}) {guild.id} : {str(guild.owner)} : {count}\n"
if x%50==0:
e = discord.Embed(description = data)
await ctx.send(embed=e)
data = ""
x+=1
e = discord.Embed(description = data)
await ctx.send(embed=e)
## PING ##
roles = eval(db.get('roles'))
warnings = eval(db.get('warnings'))
giveaways = eval(db.get('giveaways'))
notelist = eval(db.get('notelist'))
settings = eval(db.get('settings'))
levels = eval(db.get('levels'))
afks = eval(db.get('afks'))
invite_track = eval(db.get('invite_track'))
msg_count = eval(db.get('msg_count'))
punish = eval(db.get('punish'))
linklist = eval(db.get('linklist'))
commandlist = eval(db.get('commandlist'))
vote_count = eval(db.get('vote_count'))
default_welcome = """**Hello {mention}, welcome to {guild}!**
`We now have {membercount} members` :partying_face:"""
default_goodbye = """**{name} just left the server!**
`We now have {membercount} members` :frowning:"""
rr_color = 2123412
mod_color = 15548997
Color=11027200
invite_data = {}
vanities = {}
def find_invite_by_code(invite_list, code):
for inv in invite_list:
if inv.code == code:
return inv
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(client.guilds)} Servers"))
# INVITE DATA #
for guild in settings:
if 'invitelogs' in settings[guild]:
server = client.get_guild(guild)
if server!=None:
try:
invite_data[guild] = await server.invites()
if 'VANITY_URL' in server.features: vanities[guild] = (await server.vanity_invite()).uses
except: pass
# PENDING GIVEAWAYS #
pending = {}
t = time()
for guild in giveaways:
for msg in giveaways[guild]:
pending[msg] = (guild, giveaways[guild][msg][3]-t)
for msg_id in list(dict(sorted(pending.items(), key=lambda x: x[1][1]))):
t = giveaways[pending[msg_id][0]][msg_id][3]-time()
if t>0: await asyncio.sleep(t)
try:
server = client.get_guild(pending[msg_id][0])
ch = server.get_channel(giveaways[pending[msg_id][0]][msg_id][2])
msg = await ch.fetch_message(msg_id)
users = await msg.reactions[0].users().flatten()
for user in users:
if user.bot:
users.remove(user)
break
winners = choices(users,k=giveaways[pending[msg_id][0]][msg_id][0])
w_data = " "
for Winner in winners: w_data+="<@"+str(Winner.id)+"> "
data = ":confetti_ball: Congratulations" + w_data + "! You won **"+giveaways[pending[msg_id][0]][msg_id][1]+"**!"
e_data = "Winners:"+w_data+"\nHosted By: <@"+str(giveaways[pending[msg_id][0]][msg_id][4])+">"
await ch.send(data)
e = discord.Embed(title=giveaways[pending[msg_id][0]][msg_id][1], description=e_data)
e.set_footer(text=f"{giveaways[pending[msg_id][0]][msg_id][0]} Winner{'s' if giveaways[pending[msg_id][0]][msg_id][0]>1 else ''} | Ended")
e.timestamp=datetime.datetime.now()
await msg.edit(content=":tada: **GIVEAWAY ENDED** :tada:", embed=e)
del giveaways[pending[msg_id][0]][msg_id]
db.set('giveaways', str(giveaways))
except: pass
@client.event
async def on_guild_join(guild):
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(client.guilds)} Servers"))
if len(guild.members) >= 100:
server = client.get_guild(917850586358104064)
role = server.get_role(926897066859462756)
member = server.get_member(guild.owner.id)
await member.add_roles(role)
@client.command()
async def ping(ctx):
await ctx.reply(f"Pong! {round (client.latency * 1000)} ms")
## OWNER COMMANDS
@client.command()
@commands.has_permissions(administrator=True)
async def backup(ctx):
if ctx.guild.id == 917850586358104064:
file = StringIO(db[ctx.channel.name].decode('utf-8'))
await ctx.send(f"Your {ctx.channel.name} backup is:", file=discord.File(file, "result.txt"))
@client.command()
async def update(ctx):
if ctx.guild.id == 917850586358104064 and ctx.author.id==701677143033118800:
if ctx.channel.name == "roles":
for g in list(roles):
guild = client.get_guild(g)
if guild==None or roles[g]=={}:
del roles[g]
continue
for c in list(roles[g]):
channel = guild.get_channel(c)
if channel==None or roles[g][c]=={}:
del roles[g][c]
continue
for msg in list(roles[g][c]):
try: await channel.fetch_message(msg)
except: del roles[g][c][msg]
db.set('roles', str(roles))
elif ctx.channel.name == "warnings":
for guild in list(warnings):
if client.get_guild(guild)==None or warnings[guild]=={}:
del warnings[guild]
db.set('warnings', str(warnings))
elif ctx.channel.name == "giveaways":
for g in list(giveaways):
guild = client.get_guild(g)
if guild==None or giveaways[g]=={}:
del giveaways[g]
continue
for msg in list(giveaways[g]):
channel = guild.get_channel(giveaways[g][msg][2])
if channel==None:
del giveaways[g][msg]
else:
try: await channel.fetch_message(msg)
except: del giveaways[g][msg]
db.set('giveaways', str(giveaways))
elif ctx.channel.name == "notelist":
for guild in list(notelist):
if client.get_guild(guild)==None or notelist[guild]=={}:
del notelist[guild]
db.set('notelist', str(notelist))
elif ctx.channel.name == "settings":
for guild in list(settings):
if client.get_guild(guild)==None or settings[guild]=={}:
del settings[guild]
db.set('settings', str(settings))
elif ctx.channel.name == "levels":
for guild in list(levels):
if client.get_guild(guild)==None or levels[guild]=={}:
del levels[guild]
db.set('levels', str(levels))
elif ctx.channel.name == "afks":
for g in list(afks):
guild = client.get_guild(g)
if guild==None or afks[g]=={}:
del afks[g]
continue
for member in list(afks[g]):
if guild.get_member(member)==None:
del afks[g][member]
db.set('afks', str(afks))
elif ctx.channel.name == "invite_track":
for guild in list(invite_track):
if client.get_guild(guild)==None or invite_track[guild]=={}:
del invite_track[guild]
db.set('invite_track', str(invite_track))
elif ctx.channel.name == "msg_count":
for guild in list(msg_count):
if client.get_guild(guild)==None:
del msg_count[guild]
db.set('msg_count', str(msg_count))
elif ctx.channel.name == "punish":
for guild in list(punish):
if client.get_guild(guild)==None or punish[guild]=={}:
del punish[guild]
db.set('punish', str(punish))
elif ctx.channel.name == "linklist":
for guild in list(linklist[0]):
if client.get_guild(guild)==None or linklist[0][guild]=={}:
del linklist[0][guild]
for guild in list(linklist[1]):
if client.get_guild(guild)==None or linklist[1][guild]=={}:
del linklist[1][guild]
db.set('linklist', str(linklist))
elif ctx.channel.name == "commandlist":
for guild in list(commandlist):
if client.get_guild(guild)==None or commandlist[guild]=={}:
del commandlist[guild]
db.set('commandlist', str(commandlist))
else:
return
file = StringIO(db[ctx.channel.name].decode('utf-8'))
await ctx.send(f"<a:yes:923454161666863174> {ctx.channel.name} updated:", file=discord.File(file, "result.txt"))
## SUGGESTIONS ##
@client.command(aliases=["suggestion"])
@commands.has_permissions(manage_guild=True)
async def setsuggest(ctx,ch: discord.TextChannel=None):
if ch==None: ch=ctx.channel
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if 'suggestion' not in settings[ctx.guild.id]: settings[ctx.guild.id]['suggestion'] = [0,0]
settings[ctx.guild.id]['suggestion'][0] = ch.id
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the Suggestion Channel to {ch.mention}**")
@setsuggest.error
async def setsuggest_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
del settings[ctx.guild.id]['suggestion']
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the suggestions**")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command(aliases=["suggestionlogs","setsuggestionlogs","suggestlogs"])
@commands.has_permissions(manage_guild=True)
async def setsuggestlogs(ctx,ch: discord.TextChannel=None):
if ch==None: ch=ctx.channel
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if 'suggestion' not in settings[ctx.guild.id]:
await ctx.reply("<a:no:923454180427980821> **Suggestions haven't been set**, Use `!setsuggest [channel]` to set suggestions")
else:
settings[ctx.guild.id]['suggestion'][1] = ch.id
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the Suggestion Logs Channel to {ch.mention}**")
@setsuggestlogs.error
async def setsuggestlogs_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
settings[ctx.guild.id]['suggestion'][1] = 0
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the suggestion logs**")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def accept(ctx, ID:int, *, message="Accepted"):
if ctx.guild.id in settings and 'suggestion' in settings[ctx.guild.id]:
ch = ctx.guild.get_channel(settings[ctx.guild.id]['suggestion'][0])
logs = ctx.guild.get_channel(settings[ctx.guild.id]['suggestion'][1])
try: msg = await ch.fetch_message(ID)
except: msg = await logs.fetch_message(ID)
e = msg.embeds[0]
e.color=3066993
e.clear_fields()
e.add_field(name=f"Reply from {str(ctx.author)}", value=message)
e.set_footer(text='Status: Accepted')
e.timestamp=datetime.datetime.now()
if logs==None: await msg.edit(embed=e)
else:
await msg.delete()
msg = await logs.send(embed=e)
user = ctx.guild.get_member_named(e.author.name)
try:
e = discord.Embed(description=f"<:upvote:937549400287367220> **Your suggestion has been accepted.** [Message Link]({msg.jump_url})", color=3066993)
await user.send(embed=e)
except: pass
MSG = await ctx.reply("<:upvote:937549400287367220> **Suggestion Accepted**")
await ctx.message.delete()
await asyncio.sleep(1)
await MSG.delete()
@accept.error
async def accept_error(ctx,error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
@client.command(aliases=["reject"])
@commands.has_permissions(manage_guild=True)
async def deny(ctx, ID:int, *, message="Denied"):
if ctx.guild.id in settings and 'suggestion' in settings[ctx.guild.id]:
ch = ctx.guild.get_channel(settings[ctx.guild.id]['suggestion'][0])
logs = ctx.guild.get_channel(settings[ctx.guild.id]['suggestion'][1])
try: msg = await ch.fetch_message(ID)
except: msg = await logs.fetch_message(ID)
e = msg.embeds[0]
e.color=15548997
e.clear_fields()
e.add_field(name=f"Reply from {str(ctx.author)}", value=message)
e.set_footer(text='Status: Denied')
e.timestamp=datetime.datetime.now()
if logs==None: await msg.edit(embed=e)
else:
await msg.delete()
msg = await logs.send(embed=e)
user = ctx.guild.get_member_named(e.author.name)
try:
e = discord.Embed(description=f"<:downvote:937549400501264394> **Your suggestion has been denied.** [Message Link]({msg.jump_url})", color=15548997)
await user.send(embed=e)
except: pass
MSG = await ctx.reply("<:downvote:937549400501264394> **Suggestion Denied**")
await ctx.message.delete()
await asyncio.sleep(1)
await MSG.delete()
@deny.error
async def deny_error(ctx,error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
@client.command()
async def suggest(ctx, *, message):
if ctx.guild.id in settings and 'suggestion' in settings[ctx.guild.id]:
ch = ctx.guild.get_channel(settings[ctx.guild.id]['suggestion'][0])
e = discord.Embed(description=message, color=16705372)
e.set_author(name=str(ctx.author), icon_url=ctx.author.display_avatar.url)
e.set_footer(text='Status: Pending')
e.timestamp=datetime.datetime.now()
message = await ch.send(embed=e)
await message.add_reaction(client.get_emoji(937549400287367220))
await message.add_reaction(client.get_emoji(937549400501264394))
e = discord.Embed(description=f"**Your suggestion has been sent.** [Message Link]({message.jump_url})", color=16705372)
e.set_footer(text="You will get a DM on a reply over your suggestion")
await ctx.reply(embed=e)
else:
msg = await ctx.reply("<a:no:923454180427980821> **Suggestions haven't been set**, Use `!setsuggest [channel]` to set suggestions")
await asyncio.sleep(3)
await msg.delete()
@suggest.error
async def suggest_error(ctx,error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
async def bug(ctx, *, message):
e = discord.Embed(title=f"Bug Reported by {str(ctx.author)}",description=message,color=8359053)
guild = client.get_guild(917850586358104064)
ch = guild.get_channel(923440468673589298)
await ch.send(embed=e)
await ctx.reply("**<a:yes:923454161666863174> Reported the bug in support server.**")
@bug.error
async def bug_error(ctx,error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
## CONFIGURE ##
@client.command()
@commands.has_permissions(manage_guild=True)
async def welcome(ctx,ch: discord.TextChannel=None, *, msg=None):
if ch==None: ch=ctx.channel
if msg=="default": msg=default_welcome
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if 'welcome' in settings[ctx.guild.id]:
settings[ctx.guild.id]['welcome'][0]=ch.id
if msg: settings[ctx.guild.id]['welcome'][1]=msg
else:
if msg==None: msg=default_welcome
settings[ctx.guild.id]['welcome'] = [ch.id, msg]
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the Welcome Channel to {ch.mention}**")
@welcome.error
async def welcome_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the welcome message**")
del settings[ctx.guild.id]['welcome']
db.set('settings', str(settings))
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def goodbye(ctx,ch: discord.TextChannel=None, *, msg=None):
if ch==None: ch=ctx.channel
if msg=="default": msg=default_goodbye
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if 'goodbye' in settings[ctx.guild.id]:
settings[ctx.guild.id]['goodbye'][0]=ch.id
if msg: settings[ctx.guild.id]['goodbye'][1]=msg
else:
if msg==None: msg=default_goodbye
settings[ctx.guild.id]['goodbye'] = [ch.id, msg]
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the Goodbye Channel to {ch.mention}**")
@goodbye.error
async def goodbye_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the Goodbye message**")
del settings[ctx.guild.id]['goodbye']
db.set('settings', str(settings))
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
@commands.bot_has_permissions(manage_guild=True)
async def invitelogs(ctx,ch: discord.TextChannel=None):
if ch==None: ch=ctx.channel
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if ctx.guild.id not in invite_track: invite_track[ctx.guild.id] = {}
settings[ctx.guild.id]['invitelogs'] = ch.id
db.set('settings', str(settings))
db.set('invite_track', str(invite_track))
invite_data[ctx.guild.id] = await ctx.guild.invites()
if 'VANITY_URL' in ctx.guild.features: vanities[ctx.guild.id] = (await ctx.guild.vanity_invite()).uses
await ctx.reply(f"**<a:yes:923454161666863174> Set the Invite Logs Channel to {ch.mention}**")
@invitelogs.error
async def invitelogs_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the Invite Logs**")
del settings[ctx.guild.id]['invitelogs']
db.set('settings', str(settings))
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def logs(ctx,ch: discord.TextChannel=None):
if ch==None: ch=ctx.channel
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
settings[ctx.guild.id]['logs'] = ch.id
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the Logs Channel to {ch.mention}**")
@logs.error
async def logs_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the logs**")
del settings[ctx.guild.id]['logs']
db.set('settings', str(settings))
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def autorole(ctx,role: discord.Role):
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
if ctx.author.top_role.position > role.position or ctx.guild.owner == ctx.author:
settings[ctx.guild.id]['autorole'] = role.id
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the autorole to {role.name}**")
else:
await ctx.reply("<a:no:923454180427980821> You don't have perms to manage this role")
@autorole.error
async def autorole_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled the autorole**")
del settings[ctx.guild.id]['autorole']
db.set('settings', str(settings))
elif isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def counting(ctx,ch: discord.TextChannel=None):
if ch==None: ch=ctx.channel
if ctx.guild.id not in settings: settings[ctx.guild.id] = {}
settings[ctx.guild.id]['counting'] = [ch.id, 0, 0, 0]
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the counting channel to {ch.mention}**")
@counting.error
async def counting_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
args = ctx.message.content.lower().split()
if len(args)>1 and args[1]=="disable":
await ctx.reply(f"**<a:yes:923454161666863174> Disabled counting**")
del settings[ctx.guild.id]['counting']
db.set('settings', str(settings))
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def setcount(ctx, Count:int):
if Count<=0:
await ctx.reply("<a:no:923454180427980821> Count should be greater than 0")
return
if ctx.guild.id in settings and 'counting' in settings[ctx.guild.id]:
settings[ctx.guild.id]['counting'][1]=Count
settings[ctx.guild.id]['counting'][2]=0
settings[ctx.guild.id]['counting'][3]=0
db.set('settings', str(settings))
await ctx.reply(f"**<a:yes:923454161666863174> Set the count to {Count}**")
else:
await ctx.reply("**<a:no:923454180427980821> Use `!counting <channel>` to setup counting**")
@setcount.error
async def setcount_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def resetcount(ctx):
if ctx.guild.id in settings and 'counting' in settings[ctx.guild.id]:
settings[ctx.guild.id]['counting'][1]=0
settings[ctx.guild.id]['counting'][2]=0
settings[ctx.guild.id]['counting'][3]=0
db.set('settings', str(settings))
await ctx.reply("**<a:yes:923454161666863174> Resetted the count**")
else:
await ctx.reply("**<a:no:923454180427980821> Use `!counting <channel>` to setup counting**")
@resetcount.error
async def resetcount_error(ctx, error):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
async def count(ctx):
if ctx.guild.id in settings and 'counting' in settings[ctx.guild.id]:
await ctx.reply(f"<a:yes:923454161666863174> The current count is **{settings[ctx.guild.id]['counting'][1]}**")
else:
await ctx.reply("<a:no:923454180427980821> Counting isn't setted up yet")
@client.command()
@commands.has_permissions(manage_guild=True)
async def invitelinks(ctx, action, Channel: discord.TextChannel=None):
if ctx.guild.id not in linklist[0]: linklist[0][ctx.guild.id] = {}
if 'whitelist' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['whitelist'] = []
if 'blacklist' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['blacklist'] = []
if action=="disable":
linklist[0][ctx.guild.id]['disabled'] = True
if Channel==None:
if 'all' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['all'] = True
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Invitelinks**")
else:
if 'all' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['all'] = False
if not linklist[0][ctx.guild.id]['all'] and Channel.id not in linklist[0][ctx.guild.id]['whitelist']: linklist[0][ctx.guild.id]['whitelist'].append(Channel.id)
if linklist[0][ctx.guild.id]['all'] and Channel.id in linklist[0][ctx.guild.id]['blacklist']: linklist[0][ctx.guild.id]['blacklist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Invitelinks in {Channel.mention}**")
elif action=="enable":
if Channel==None:
linklist[0][ctx.guild.id]['disabled'] = False
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Invitelinks**")
else:
if linklist[0][ctx.guild.id]['all'] and Channel.id not in linklist[0][ctx.guild.id]['blacklist']: linklist[0][ctx.guild.id]['blacklist'].append(Channel.id)
if not linklist[0][ctx.guild.id]['all'] and Channel.id in linklist[0][ctx.guild.id]['whitelist']: linklist[0][ctx.guild.id]['whitelist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Invitelinks in {Channel.mention}**")
else:
await ctx.reply(f"**<a:no:923454180427980821> Invalid Command -> `!invitelinks <enable/disable> [all/channel]`**")
db.set('linklist', str(linklist))
@invitelinks.error
async def invitelinks_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
if ctx.guild.id not in linklist[0]: linklist[0][ctx.guild.id] = {}
if 'whitelist' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['whitelist'] = []
if 'blacklist' not in linklist[0][ctx.guild.id]: linklist[0][ctx.guild.id]['blacklist'] = []
args = ctx.message.content.lower().split()
if len(args)>2 and args[1]=="disable" and args[2]=="all":
linklist[0][ctx.guild.id]['disabled'] = True
linklist[0][ctx.guild.id]['whitelist'] = []
linklist[0][ctx.guild.id]['blacklist'] = []
linklist[0][ctx.guild.id]['all'] = True
db.set('linklist', str(linklist))
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Invitelinks in all channels**")
elif len(args)>2 and args[1]=="enable" and args[2]=="all":
linklist[0][ctx.guild.id]['disabled'] = False
linklist[0][ctx.guild.id]['whitelist'] = []
linklist[0][ctx.guild.id]['blacklist'] = []
linklist[0][ctx.guild.id]['all'] = False
db.set('linklist', str(linklist))
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Invitelinks in all channels**")
elif isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def links(ctx, action, Channel: discord.TextChannel=None):
if ctx.guild.id not in linklist[1]: linklist[1][ctx.guild.id] = {}
if 'whitelist' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['whitelist'] = []
if 'blacklist' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['blacklist'] = []
if action=="disable":
linklist[1][ctx.guild.id]['disabled'] = True
if Channel==None:
if 'all' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['all'] = True
await ctx.reply(f"**<a:yes:923454161666863174> Disabled links**")
else:
if 'all' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['all'] = False
if not linklist[1][ctx.guild.id]['all'] and Channel.id not in linklist[1][ctx.guild.id]['whitelist']: linklist[1][ctx.guild.id]['whitelist'].append(Channel.id)
if linklist[1][ctx.guild.id]['all'] and Channel.id in linklist[1][ctx.guild.id]['blacklist']: linklist[1][ctx.guild.id]['blacklist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Disabled links in {Channel.mention}**")
elif action=="enable":
if Channel==None:
linklist[1][ctx.guild.id]['disabled'] = False
await ctx.reply(f"**<a:yes:923454161666863174> Enabled links**")
else:
if linklist[1][ctx.guild.id]['all'] and Channel.id not in linklist[1][ctx.guild.id]['blacklist']: linklist[1][ctx.guild.id]['blacklist'].append(Channel.id)
if not linklist[1][ctx.guild.id]['all'] and Channel.id in linklist[1][ctx.guild.id]['whitelist']: linklist[1][ctx.guild.id]['whitelist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Enabled links in {Channel.mention}**")
else:
await ctx.reply(f"**<a:no:923454180427980821> Invalid Command -> `!links <enable/disable> [all/channel]`**")
db.set('linklist', str(linklist))
@links.error
async def links_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
if ctx.guild.id not in linklist[1]: linklist[1][ctx.guild.id] = {}
if 'whitelist' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['whitelist'] = []
if 'blacklist' not in linklist[1][ctx.guild.id]: linklist[1][ctx.guild.id]['blacklist'] = []
args = ctx.message.content.lower().split()
if len(args)>2 and args[1]=="disable" and args[2]=="all":
linklist[1][ctx.guild.id]['disabled'] = True
linklist[1][ctx.guild.id]['whitelist'] = []
linklist[1][ctx.guild.id]['blacklist'] = []
linklist[1][ctx.guild.id]['all'] = True
db.set('linklist', str(linklist))
await ctx.reply(f"**<a:yes:923454161666863174> Disabled links in all channels**")
elif len(args)>2 and args[1]=="enable" and args[2]=="all":
linklist[1][ctx.guild.id]['disabled'] = False
linklist[1][ctx.guild.id]['whitelist'] = []
linklist[1][ctx.guild.id]['blacklist'] = []
linklist[1][ctx.guild.id]['all'] = False
db.set('linklist', str(linklist))
await ctx.reply(f"**<a:yes:923454161666863174> Enabled links in all channels**")
elif isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def leveling(ctx, action, Channel: discord.TextChannel=None):
if ctx.guild.id not in levels: levels[ctx.guild.id] = {}
if 'whitelist' not in levels[ctx.guild.id]: levels[ctx.guild.id]['whitelist'] = []
if 'blacklist' not in levels[ctx.guild.id]: levels[ctx.guild.id]['blacklist'] = []
if action=="enable":
levels[ctx.guild.id]['enabled'] = True
if Channel==None:
if 'all' not in levels[ctx.guild.id]: levels[ctx.guild.id]['all'] = True
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Leveling**")
else:
if 'all' not in levels[ctx.guild.id]: levels[ctx.guild.id]['all'] = False
if not levels[ctx.guild.id]['all'] and Channel.id not in levels[ctx.guild.id]['whitelist']: levels[ctx.guild.id]['whitelist'].append(Channel.id)
if levels[ctx.guild.id]['all'] and Channel.id in levels[ctx.guild.id]['blacklist']: levels[ctx.guild.id]['blacklist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Leveling in {Channel.mention}**")
elif action=="disable":
if Channel==None:
levels[ctx.guild.id]['enabled'] = False
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Leveling**")
else:
if levels[ctx.guild.id]['all'] and Channel.id not in levels[ctx.guild.id]['blacklist']: levels[ctx.guild.id]['blacklist'].append(Channel.id)
if not levels[ctx.guild.id]['all'] and Channel.id in levels[ctx.guild.id]['whitelist']: levels[ctx.guild.id]['whitelist'].remove(Channel.id)
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Leveling in {Channel.mention}**")
else:
await ctx.reply(f"**<a:no:923454180427980821> Invalid Command -> `!leveling <enable/disable> [all/channel]`**")
db.set('levels', str(levels))
@leveling.error
async def leveling_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
return
if ctx.guild.id not in levels: levels[ctx.guild.id] = {}
if 'whitelist' not in levels[ctx.guild.id]: levels[ctx.guild.id]['whitelist'] = []
if 'blacklist' not in levels[ctx.guild.id]: levels[ctx.guild.id]['blacklist'] = []
args = ctx.message.content.lower().split()
if len(args)>2 and args[1]=="enable" and args[2]=="all":
levels[ctx.guild.id]['enabled'] = True
levels[ctx.guild.id]['whitelist'] = []
levels[ctx.guild.id]['blacklist'] = []
levels[ctx.guild.id]['all'] = True
db.set('levels', str(levels))
await ctx.reply(f"**<a:yes:923454161666863174> Enabled Leveling in all channels**")
elif len(args)>2 and args[1]=="disable" and args[2]=="all":
levels[ctx.guild.id]['enabled'] = False
levels[ctx.guild.id]['whitelist'] = []
levels[ctx.guild.id]['blacklist'] = []
levels[ctx.guild.id]['all'] = False
db.set('levels', str(levels))
await ctx.reply(f"**<a:yes:923454161666863174> Disabled Leveling in all channels**")
elif isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command(aliases=["addlr"])
@commands.has_permissions(manage_guild=True)
async def addlevelreward(ctx, level: int, role:discord.Role):
if not level:
await ctx.reply("**<a:no:923454180427980821> Level should be more than 0**")
return
if ctx.guild.id not in levels: levels[ctx.guild.id] = {}
if 'rewards' not in levels[ctx.guild.id]: levels[ctx.guild.id]['rewards'] = {}
levels[ctx.guild.id]['rewards'][level] = role.id
await ctx.reply(f"<a:yes:923454161666863174> Added **{role.name}** for level **{level}**")
db.set('levels', str(levels))
@addlevelreward.error
async def addlevelreward_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command(aliases=["removelr"])
@commands.has_permissions(manage_guild=True)
async def removelevelreward(ctx, level: int):
if not level:
await ctx.reply("**<a:no:923454180427980821> Level should be more than 0**")
return
try:
del levels[ctx.guild.id]['rewards'][level]
await ctx.reply(f"<a:yes:923454161666863174> Removed **level {level}** reward")
db.set('levels', str(levels))
except:
await ctx.reply(f"<a:no:923454180427980821> No reward for **level {level}**")
@removelevelreward.error
async def removelevelreward_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command(aliases=["lrs"])
async def levelrewards(ctx):
if ctx.guild.id in levels and 'rewards' in levels[ctx.guild.id]:
data = ""
for level in levels[ctx.guild.id]['rewards']:
data += f"**Level {level}** -> <@&{levels[ctx.guild.id]['rewards'][level]}>\n"
e = discord.Embed(title=f"{ctx.guild.name}'s level rewards", description=data)
await ctx.reply(embed=e)
@client.command(aliases=['level'])
async def rank(ctx, user: discord.Member=None):
if user==None: user=ctx.author
if ctx.guild.id in levels and levels[ctx.guild.id]['enabled']:
if user.id in levels[ctx.guild.id]['data']:
data = f"""**Rank** -> {list(dict(sorted(levels[ctx.guild.id]['data'].items(), key=lambda x: x[1], reverse=True))).index(user.id)+1}
**Level** -> {levels[ctx.guild.id]['data'][user.id][0]}
**XP** -> {levels[ctx.guild.id]['data'][user.id][1]}/{50*(levels[ctx.guild.id]['data'][user.id][0]+1)*(levels[ctx.guild.id]['data'][user.id][0]+2)}"""
else:
data = "**You are Rank 1**\n||From the last :rofl:||"
e = discord.Embed(title=str(user), description=data, color=user.color)
e.set_thumbnail(url=user.display_avatar.url)
await ctx.reply(embed=e)
else:
await ctx.reply("<a:no:923454180427980821> Leveling is disabled in this guild!")
@client.command()
@commands.has_permissions(manage_guild=True)
async def setlevel(ctx, user:discord.Member, level:int):
if ctx.guild.id in levels and levels[ctx.guild.id]['enabled']:
if level<0:
await ctx.reply("<a:no:923454180427980821> Level can't be negative")
else:
if 'data' not in levels[ctx.guild.id]: levels[ctx.guild.id]['data'] = {}
if user.id not in levels[ctx.guild.id]['data']: levels[ctx.guild.id]['data'][user.id] = [0,0,0]
levels[ctx.guild.id]['data'][user.id][0] = level
levels[ctx.guild.id]['data'][user.id][1] = (level)*(level+1)*50
await ctx.reply(f"<a:yes:923454161666863174> Changed **{user.name}'s** level to **{level}**")
db.set('levels', str(levels))
else:
await ctx.reply("<a:no:923454180427980821> Use `!leveling enable` to enable leveling!")
@setlevel.error
async def setlevel_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
prefix = settings[ctx.guild.id]['prefix'] if ctx.guild.id in settings and 'prefix' in settings[ctx.guild.id] else default_prefix
await ctx.reply(f"<a:no:923454180427980821> **Invalid Syntax**, Use `{prefix+helplist[ctx.command.name][2]}`")
else:
await ctx.reply(f"**<a:no:923454180427980821> {error}**")
@client.command()
@commands.has_permissions(manage_guild=True)
async def resetlevels(ctx):
if ctx.guild.id in levels and 'data' in levels[ctx.guild.id]:
del levels[ctx.guild.id]['data']