generated from kkrypt0nn/Python-Discord-Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
Β·216 lines (192 loc) Β· 7.6 KB
/
bot.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
"""
Copyright vk3dan 2021
Description:
This is lidbot, a bot for lids.
It has some fairly basic features, some from the template used, and
some written by myself, with some more hopefully coming soon.
Template used Copyright Β© Krypton 2021 - https://github.com/kkrypt0nn
Description from template:
This is a template to create your own discord bot in python.
Version: 2.3
"""
import discord, asyncio, os, platform, sys, random, requests, json
from discord.ext.commands import Bot
from discord.ext import commands
from discord import Webhook, RequestsWebhookAdapter
from discord.utils import get
if not os.path.isfile("config.py"):
sys.exit("'config.py' not found! Please add it and try again.")
else:
import config
"""
Setup bot intents (events restrictions)
For more information about intents, please go to the following websites:
https://discordpy.readthedocs.io/en/latest/intents.html
https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents
Default Intents:
intents.messages = True
intents.reactions = True
intents.guilds = True
intents.emojis = True
intents.bans = True
intents.guild_typing = False
intents.typing = False
intents.dm_messages = False
intents.dm_reactions = False
intents.dm_typing = False
intents.guild_messages = True
intents.guild_reactions = True
intents.integrations = True
intents.invites = True
intents.voice_states = False
intents.webhooks = False
Privileged Intents (Needs to be enabled on dev page):
intents.presences = True
intents.members = True
"""
intents = discord.Intents.default()
intents.members = True
ser_pref={'845344210231623690':'?'}
def get_prefix(bot, msg):
try:
return ser_pref[str(msg.guild.id)]
except:
return config.BOT_PREFIX
bot = Bot(command_prefix=get_prefix, intents=intents, case_insensitive=True)
statuses = ['like a lid', 'with a baofeng', 'with myself', 'with my ding-ding',
'you.', 'myself', 'with fireworks in garage', 'with matches', 'guitar', 'sportsball',
'tag', 'ball', 'hardball', 'the fool', 'a doctor on tv', 'around', 'VHS tapes',
'hard to get', 'basketball', 'football', 'stupid games', 'with SSTV', 'on Brandmeister',
'on TGIF', 'on 98003', 'Gonk Simulator', 'THE GAME. You just lost.', 'with velcro']
penguins = {'There are always worse things, like penguin herpes.':'kd1ldo', 'Did you sexually abuse penguins?':'W0CSG', 'PENGWINS.':'W0CSG'}
gonksimeditions = [' ', '2', '3', '- Remastered', '2020: Gonkdemic', '2021', '2022',
'2047: Gonkout', 'for kids', 'with bacon', 'for linux']
# The code in this even is executed when the bot is ready
@bot.event
async def on_ready():
bot.loop.create_task(status_task())
print(f"Logged in as {bot.user.name}")
print(f"Discord.py API version: {discord.__version__}")
print(f"Python version: {platform.python_version()}")
print(f"Running on: {platform.system()} {platform.release()} ({os.name})")
print("-------------------")
# Setup the game status task of the bot
async def status_task():
await bot.wait_until_ready()
while True:
currentstatus=random.choice(statuses)
if currentstatus=="Gonk Simulator":
currentstatus=f"{currentstatus} {random.choice(gonksimeditions)}"
await bot.change_presence(activity=discord.Game(currentstatus))
await asyncio.sleep(60)
# Removes the default help command of discord.py to be able to create our custom help command.
bot.remove_command("help")
if __name__ == "__main__":
for extension in config.STARTUP_COGS:
try:
bot.load_extension(extension)
extension = extension.replace("cogs.", "")
print(f"Loaded extension '{extension}'")
except Exception as e:
exception = f"{type(e).__name__}: {e}"
extension = extension.replace("cogs.", "")
print(f"Failed to load extension {extension}\n{exception}")
# The code in this event is executed every time someone sends a message, with or without the prefix
@bot.event
async def on_message(message):
# Ignores if a command is being executed by a bot or by the bot itself
if message.author == bot.user or message.author.bot:
return
else:
if message.author.id not in config.BLACKLIST:
# Process the command if the user is not blacklisted
startwords=("73","73s","hi ","heya","ohaider","π","night","later","l8r","l9r")
endwords=(" 73"," 73s","nini"," gn"," night"," l8r"," l9r","π")
if message.content.lower().startswith(tuple(startwords)) or message.content.lower().endswith(tuple(endwords)):
await message.add_reaction("π")
elif message.content == "88":
await message.add_reaction("π«")
await message.add_reaction("π")
elif "gonk" in message.content.lower() and not message.content.startswith("!"):
await message.add_reaction("π¬")
await message.add_reaction("π΄")
await message.add_reaction("π³")
await message.add_reaction("π°")
elif "penguin" in message.content.lower() or "π§" in message.content:
webhook = await message.channel.create_webhook(name="lidstuff")
penguinquote, penguinnick = random.choice(list(penguins.items()))
await webhook.send(penguinquote, username=penguinnick, avatar_url="http://clipart-library.com/image_gallery2/Penguin-PNG-Picture.png")
await webhook.delete()
await bot.process_commands(message)
else:
# Send a message to let the user know he's blacklisted
context = await bot.get_context(message)
embed = discord.Embed(
title="You're blacklisted!",
description="Ask the owner to remove you from the list if you think it's not normal.",
color=0xFF0000
)
await context.send(embed=embed)
@bot.event
async def on_raw_reaction_add(payload):
if payload.user_id == bot.user.id:
return
else:
if payload.user_id not in config.BLACKLIST:
# Process the command if the user is not blacklisted
if payload.emoji.name == "π":
guild=bot.get_guild(payload.guild_id)
channel=bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
reaction = get(msg.reactions, emoji=payload.emoji.name)
if reaction and reaction.count > 1:
return
reactor=payload.member
name=msg.author.display_name
quote=msg.content
quotefile=f"resources/{payload.guild_id}quotes.json"
justincaseempty=open(quotefile,"a")
justincaseempty.close
with open(quotefile,"r") as quotejson:
try:
data = json.loads(quotejson.read())
except:
data={}
quotes={}
quotenum=len(data)+1
quotes[int(quotenum)]={
'name':name,
'quote':quote
}
data.update(quotes)
data=json.dumps(data)
with open(quotefile,"w") as quotejson:
quotejson.write(data)
embed = discord.Embed(
title="Quote added",
description=f"Added quote {quotenum} - \"{name}: {quote}\" to quotes",
color=0x00FF00
)
webhook = await channel.create_webhook(name="lidstuff")
await webhook.send(embed=embed, username=reactor.display_name, avatar_url=reactor.avatar_url)
await webhook.delete()
# The code in this event is executed every time a command has been *successfully* executed
@bot.event
async def on_command_completion(ctx):
fullCommandName = ctx.command.qualified_name
split = fullCommandName.split(" ")
executedCommand = str(split[0])
print(f"Executed {executedCommand} command in {ctx.guild.name} by {ctx.message.author} (ID: {ctx.message.author.id})")
# The code in this event is executed every time a valid commands catches an error
@bot.event
async def on_command_error(context, error):
if isinstance(error, commands.CommandOnCooldown):
embed = discord.Embed(
title="Error!",
description="This command is on a %.2fs cooldown" % error.retry_after,
color=0xFF0000
)
await context.send(embed=embed)
raise error
# Run the bot with the token
bot.run(config.TOKEN)