-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmybot.py
More file actions
429 lines (312 loc) · 13.2 KB
/
Copy pathmybot.py
File metadata and controls
429 lines (312 loc) · 13.2 KB
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
import os
import praw
import random
import tweepy
import discord
from dotenv import load_dotenv
from discord.ext import commands
#loads the .env file
load_dotenv()
"""
You can use any prefix instead of '#'
just make the required changes , for now I'm using '#'
"""
#the prefix of the bot is '#'
client = commands.Bot(command_prefix = "#")
#removing the default help command so that we can make our own custom help command
client.remove_command("help")
#Rules for Your server
rules = [":one: <rule 1>", #write 1st rule in <rule1 1>
":two: <rule 2>",
":three: <rule 3>",
"", # write rules 4, 5 , 6 also here
"",
"",
":seven: <your institute> >>> any other college ." ]
filtered_words = ["fuck"] # you can add more words to filter
# suggestions for words to filter are welcome :)
# prints bot is ready on the terminal when it is online
@client.event
async def on_ready():
print("Bot is ready")
# executed whenever a message is ent on your server
@client.event
async def on_message(msg):
"""
prevent the filtered words from being used in your server
warns the person who uses these words in dm and deltes the message containing filtered words
"""
for word in filtered_words:
if word in msg.content.lower():
await msg.delete()
await msg.author.send("Don't use bad words")
# adds the reaction 😂 if someone says lol
if "lol" in msg.content.lower():
await msg.add_reaction("😂")
# adds the reaction 🤣 is someone says lmao
if "lmao" in msg.content.lower():
await msg.add_reaction("🤣")
# adds the reaction 🆒 if someone says cool
if "cool" in msg.content.lower():
await msg.add_reaction("🆒")
try:
if msg.mentions[0] == client.user:
await msg.channel.send("My prefix is '#'") #sends this when someone mentions @YOUR_BOT
except:
pass
await client.process_commands(msg)
# for exception handling
@client.event
async def on_command_error(ctx, exception):
exception = getattr(exception, "original", exception)
if isinstance(exception, commands.MissingPermissions):
await ctx.send("You can't do that 😂")
elif isinstance(exception, commands.MissingRequiredArgument):
await ctx.send("Please enter all the required arguments 🤦🏻♂️")
else:
raise exception
# help command
@client.group(invoke_without_command = True)
async def help(ctx):
em = discord.Embed(title = "Help", description = "Use #help <command> for extended information of a command.", colour = ctx.author.colour)
em.add_field(name = "Rules", value = "#rule rule_no.", inline = True)
em.add_field(name = "info", value = "#whois or #info or #user", inline = True)
em.add_field(name = "Moderation", value = "kick,ban,unban,mute,unmute,clear", inline = True)
em.add_field(name = "Poll" , value = "#poll <option1> or <option2>", inline = True)
em.add_field(name = "fun", value ="hello, meme, lol, lmao", inline = True)
await ctx.send(embed = em)
# subcommands of help command
@help.command()
async def kick(ctx):
em = discord.Embed(title = "kick", description = "kicks a member from the guild", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#kick <member> [reason]")
await ctx.send(embed=em)
@help.command()
async def ban(ctx):
em = discord.Embed(title = "ban", description = "bans a member from the guild", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#ban <member> [reason]")
await ctx.send(embed=em)
@help.command()
async def unban(ctx):
em = discord.Embed(title = "unban", description = "unbans a member who was banned from the guild", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#unban <member> ")
await ctx.send(embed=em)
@help.command()
async def mute(ctx):
em = discord.Embed(title = "mute", description = "prevents a member from sending messages", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#mute <member> ")
await ctx.send(embed=em)
@help.command()
async def unmute(ctx):
em = discord.Embed(title = "unmute", description = "unmutes a muted member", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#unmute <member> ")
await ctx.send(embed=em)
@help.command()
async def clear(ctx):
em = discord.Embed(title = "clear", description = "deltes the last <n> messages from the channel", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#clear <no. of messages to be deleted>")
em.add_field(name = "Note", value = "use #clear to delete the last message")
em.add_field(name = "Also" , value = "you can delete max. 20 messages, bcoz ishaan fixed the upper limit")
await ctx.send(embed=em)
@help.command()
async def rule(ctx):
em = discord.Embed(title = "rule", description = "send the rules of the server", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#rule <rule no.> ")
await ctx.send(embed=em)
@help.command()
async def whois(ctx):
em = discord.Embed(title = "whois", description = "send the user info of mentioned user", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#whois <member> ")
await ctx.send(embed=em)
@help.command()
async def poll(ctx):
em = discord.Embed(title = "poll", description = "sends a poll consisting of two options", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#poll <option 1> or <option 2> ")
await ctx.send(embed=em)
@help.command()
async def meme(ctx):
em = discord.Embed(title = "meme", description = "sends a random meme", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#meme")
await ctx.send(embed=em)
@help.command()
async def hello(ctx):
em = discord.Embed(title = "hello", description = "try it out", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#hello")
await ctx.send(embed=em)
#todo
"""
@help.command()
async def fire(ctx):
em = discord.Embed(title = "fire", description = "try it out", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#fire")
await ctx.send(embed=em)
"""
@help.command()
async def lol(ctx):
em = discord.Embed(title = "lol", description = "try it out", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#lol")
await ctx.send(embed=em)
@help.command()
async def lmao(ctx):
em = discord.Embed(title = "lmao", description = "try it out", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#lmao")
await ctx.send(embed=em)
@help.command()
async def cool(ctx):
em = discord.Embed(title = "cool", description = "try it out", colour = ctx.author.colour)
em.add_field(name = "**Syntax**", value = "#cool")
await ctx.send(embed=em)
# the commands
@client.command()
async def hello(ctx):
await ctx.send("Hi")
@client.command()
async def rule(ctx,*,number):
await ctx.send(rules[int(number) - 1])
clr_max = 20
@client.command(aliases=['clr'])
@commands.has_permissions(manage_messages = True)
async def clear(ctx, amount = 1):
if amount <= clr_max:
await ctx.channel.purge(limit = amount + 1)
else:
await ctx.send("You can't delete so many messages")
@client.command(aliases=['k'])
@commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member,*,reason = "No Reason Provided"):
await member.send('You have been kicked from "freshers tech club", because : ' + reason)
await ctx.send('You have been kicked from "freshers tech club", because : ' + reason)
await member.kick(reason = reason)
@client.command(aliases=['b'])
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member,*,reason = "No Reason Provided"):
try:
await ctx.send(member.name + ' have been banned from "freshers tech club", because : ' + reason)
except:
await ctx.send("The member has their dms closed.")
await member.ban(reason = reason)
@client.command(aliases=['ub'])
@commands.has_permissions(ban_members = True)
async def unban(ctx,*,member : discord.Member):
banned_users = await ctx.guild.bans()
member_name, member_disc = member.split('#')
for banned_entry in banned_users:
user = banned_entry.user
if(user.name, user.discriminator)==(member_name,member_disc):
await ctx.guild.unban(user)
await ctx.send(member_name + "has been unbanned!")
return
await ctx.send(member+" was not found")
MUTED = int(os.getenv('MUTED_ROLE_ID'))
@client.command(aliases=['m'])
@commands.has_permissions(kick_members = True)
async def mute(ctx, *, member : discord.Member):
muted_role = ctx.guild.get_role(MUTED)
await member.add_roles(muted_role)
await ctx.send(member.mention + " has been muted")
@client.command(aliases=['um'])
@commands.has_permissions(kick_members = True)
async def unmute(ctx, *, member : discord.Member):
muted_role = ctx.guild.get_role(MUTED)
await member.remove_roles(muted_role)
await ctx.send(member.mention + " has been unmuted")
@client.command()
async def lol(ctx):
await msg.delete()
await ctx.send("😂")
@client.command()
async def lmao(ctx):
await msg.delete()
await ctx.send("🤣")
@client.command()
async def cool(ctx):
await ctx.send("🆒")
#todo issue here
"""
@client.command()
async def fire(ctx:
await msg.delete()
await ctx.send("🔥")
"""
# sends information about the mentioned user
@client.command(aliases=['user', 'info'])
async def whois(ctx, member : discord.Member):
embed = discord.Embed(title = member.name, description = member.mention, colour = discord.Colour.green())
embed.add_field(name = "ID", value = member.id, inline = True)
embed.set_thumbnail(url = member.avatar_url)
embed.set_footer(icon_url = ctx.author.avatar_url, text = f"Requested by {ctx.author.name}")
await ctx.send(embed = embed)
# meme command using reddit
reddit_client_id = os.getenv('CLIENT_ID')
reddit_client_secret = os.getenv('CLIENT_SECRET')
reddit_user_agent = os.getenv('USER_AGENT')
reddit = praw.Reddit(client_id = reddit_client_id,
client_secret = reddit_client_secret,
user_agent = reddit_user_agent)
"""
This command sends a random meme from the top 10 memes tredending on reddit
"""
@client.command()
async def meme(ctx):
memes_submissions = reddit.subreddit('memes').hot()
post_to_pick = random.randint(1, 10)
for i in range(0, post_to_pick):
submission = next(x for x in memes_submissions if not x.stickied)
await ctx.send(submission.url)
#poll command
# sends a poll consisting of two options seperated by 'or'
@client.command(aliases = ['pl'])
async def poll(ctx,*,msg):
channel = ctx.channel
try:
op1, op2 = msg.split("or")
txt = f"React with ✅ for {op1} or ❎ for {op2}"
except:
await channel.send("Correct Syntax: [Choice1] or [Choice2]")
return
embed = discord.Embed(title = "Poll", description = txt, colour = discord.Colour.red() )
message_ = await channel.send(embed=embed)
await message_.add_reaction("✅")
await message_.add_reaction("❎")
await ctx.message.delete()
# twitter commands
#personal information
consumer_key = os.getenv('CONSUMER_KEY')
consumer_secret = os.getenv('CONSUMER_SECRET')
access_token = os.getenv('ACCESS_TOKEN')
access_token_secret = os.getenv('ACCES_TOKEN_SECRET')
# authentication of consumer key and secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# twitter client_id
twitter_client_id = api.me().id
# tweet command
@client.command()
async def tweet(ctx, *, msg):
api.update_status(status = msg)
tweet = api.user_timeline(id = twitter_client_id, count = 1)[0]
tweet_text = tweet.text
#print(tweet.text)
tweet_url = "https://twitter.com/<your_twitter_tagname>/status/" + str(tweet.id)
for DGuild in client.guilds:
for DChannel in DGuild.text_channels:
if DChannel.name == 'testing':
embed = discord.Embed(title = tweet.user.screen_name, description = tweet_text, colour = discord.Colour.blue())
embed.add_field(name = "TWEET ID", value = tweet.id, inline = True)
embed.add_field(name = "TWEET URL", value = tweet_url, inline = True)
embed.set_thumbnail(url = tweet_url)
embed.set_footer(icon_url = ctx.author.avatar_url, text = f"Posted by {ctx.author.name}")
embed.set_author(name='@your_twitter_tagname', icon_url=client.user.default_avatar_url)
await DChannel.send(embed = embed)
#todo wip
"""
@client.command()
async def TWEET(ctx, *, amount = 2):
messages = await ctx.channel.history(limit=amount).flatten()
TWEET_text = messages[0]
await ctx.send(TWEET_text)
"""
TOKEN = os.getenv('DISCORD_TOKEN')
client.run(TOKEN)