-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
76 lines (67 loc) · 1.84 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
import logging
import yaml
from datetime import datetime
from utils.database import Database
from utils.help import HelpCommand
import disnake
from disnake.ext import commands
# Setting up Logging
logging.basicConfig(
format='[%(asctime)s][%(levelname)s][%(name)s]: %(message)s',
level=logging.INFO
)
log = logging.getLogger('bot')
# Load configurations
cfg = yaml.safe_load(open('config.yml', 'r'))
log.info('Starting disnake {0} {1}...'.format(
disnake.__version__, disnake.version_info.releaselevel
))
intents = disnake.Intents(
guilds=True,
message_content=True,
messages=True,
guild_messages=True,
dm_messages=True
)
# Initialize Bot Class
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(cfg['bot']['prefix']),
help_command=HelpCommand(),
intents=intents,
allowed_mentions=disnake.AllowedMentions(
everyone=False,
users=True,
roles=False,
replied_user=False
),
status=disnake.Status.online,
activity=disnake.Activity(
type=disnake.ActivityType.playing,
name=f'with Emojis | Help: {cfg["bot"]["prefix"]}help'
),
sync_commands=True,
sync_commands_debug=True
)
# Connect MySQL Database
bot.db = Database(
host=cfg['mysql']['host'],
port=cfg['mysql']['port'],
user=cfg['mysql']['user'],
password=cfg['mysql']['password'],
database=cfg['mysql']['database']
)
# Bot start time for uptime stats
bot.start_time = datetime.now()
# After bot ready actions
async def after_bot_ready():
await bot.wait_until_ready()
# Connect Database
await bot.db.connect()
bot.loop.create_task(after_bot_ready())
# Loading Cogs
bot.load_extension('cogs.events')
bot.load_extension('cogs.emoji')
bot.load_extensions('cogs/app_commands')
bot.load_extensions('cogs/text_commands')
# Running Bot from Bot Token
bot.run(cfg['bot']['token'])