-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (61 loc) · 2.52 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
# RazBot new boy edition
import asyncio
import traceback
import aiomysql
import discord
from discord import app_commands
from discord.ext import commands
import yaml
from discord import app_commands
import logging, logging.handlers
cogs = ['cogs.management.database', 'cogs.moderation.mod', 'cogs.management.admin', 'cogs.fun.fun',
'cogs.management.permissions', 'cogs.management.settings', 'cogs.tools.yt2mp4', 'cogs.tools.reaction_roles', 'cogs.tools.remindme', 'cogs.fun.music', 'cogs.management.convert']
print("Imported libs. RazBot is starting...")
with open("config.yml", 'r') as yaml_read:
config = yaml.safe_load(yaml_read)
with open("token.yml", 'r') as yaml_read:
tokens = yaml.safe_load(yaml_read)
description = '''This is the RazBot rewrite.'''
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', description=description, intents=intents)
logger = logging.getLogger('discord')
logger.setLevel(logging.ERROR)
handler = logging.handlers.RotatingFileHandler(
filename='razbot.log',
encoding='utf-8',
)
dt_fmt = '%Y-%m-%d %H:%M:%S'
formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
handler.setFormatter(formatter)
logger.addHandler(handler)
async def main():
async with bot:
for cog in cogs: # Looks for the cogs,
await bot.load_extension(cog) # Loads the cogs.
print(f"Loaded cog: {cog}")
try:
pool = await aiomysql.create_pool(host=tokens["database_info"]["host"], port=3306,
user=tokens["database_info"]["username"],
password=tokens["database_info"]["password"],
db='razbotxy_botDB')
bot.pool = pool
await bot.start(tokens["secret_stuff"]["token"])
except KeyboardInterrupt:
print("Bye!")
pool.close()
await pool.wait_closed()
await bot.close()
@bot.event
async def on_command_error(ctx, error):
traceback.print_exc()
if isinstance(error, commands.CommandNotFound):
await ctx.send(f"Unknown command, sorry. Use `{ctx.prefix}help` to view a list of commands.")
elif isinstance(error, commands.MissingPermissions):
await ctx.send("Hey! Sorry but you don't have perms for that command. Duh-Doy!")
else:
raise error
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')
asyncio.run(main())