-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
61 lines (54 loc) · 2.06 KB
/
index.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
import discord
import aiomysql
import os
import utils
import asyncio
from discord.ext import commands
DB_PASSWORD=utils.DB_PASSWORD
DB_HOST=utils.DB_HOST
DB_USER=utils.DB_USER
ENV_COLOUR=utils.ENV_COLOUR
TOKEN=utils.TOKEN
async def get_prefix(client, message):
if not message.guild:
return commands.when_mentioned_or(';')(client, message)
pool = await aiomysql.create_pool(host=DB_HOST, user=DB_USER,
password=DB_PASSWORD, db='servers', autocommit=True)
prefix = ';'
async with pool.acquire() as conn:
async with conn.cursor() as cursor:
try:
await cursor.execute(
f'''SELECT prefix from configurations where guild='{message.guild.id}';''')
result = await cursor.fetchall()
if not result:
await cursor.execute(
f'''INSERT INTO configurations VALUES('{message.guild.id}',';','False',NULL,'False',NULL,NULL,'False',NULL,'False',NULL,NULL,3,5);''')
await conn.commit()
prefix = ';'
else:
prefix = result[0][0]
except:
await cursor.execute(
f'''INSERT INTO configurations VALUES('{message.guild.id}',';','False',NULL,'False',NULL,NULL,'False',NULL,'False',NULL,NULL,3,5);''')
await conn.commit()
prefix = ';'
pool.close()
await pool.wait_closed()
return commands.when_mentioned_or(prefix)(client, message)
intents = discord.Intents.default()
intents.members = True
intents.presences=True
intents.message_content=True
bot= commands.AutoShardedBot(command_prefix=get_prefix, intents=intents, case_insensitive=True)
bot.remove_command('help')
async def load_extensions():
for file in os.listdir("cogs"):
if file.endswith(".py"):
name = file[:-3]
await bot.load_extension(f"cogs.{name}")
async def main():
async with bot:
await load_extensions()
await bot.start(TOKEN)
asyncio.run(main())