-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
56 lines (42 loc) · 1.46 KB
/
__init__.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
"""
File: /bot/__init__.py
Usage: The bot's main file.
"""
from discord import Object as DiscordObject
from discord.ext.commands import Bot as BotBase
from . import config
from .data import database
from glob import glob
import logging
import os
_log = logging.getLogger(__name__)
__version__ = "1.0.0"
class Bot(BotBase):
def __init__(self, *args, **kwargs):
self.version = kwargs.get("version", "N/A")
self.ready = False
super().__init__(*args, **kwargs)
async def load_extensions(self):
# Original code from pycord
cogs = [
path.split(os.sep)[-1][:-3]
for path in glob(f"{os.path.realpath(os.path.dirname(__file__))}/cogs/*.py")
]
for cog in cogs:
_log.info(f"Bot: Loading Extension {cog}")
await self.load_extension(f"bot.cogs.{cog}")
await self.sync_commands()
async def setup_hook(self):
await super().setup_hook()
self.loop.create_task(self.load_extensions())
async def sync_commands(self):
for guildid in config.Bot.Guilds:
guild = await self.fetch_guild(guildid)
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
async def on_ready(self):
if not self.ready:
self.ready = True
_log.info(f"Bot Online | {self.user} | {self.user.id}")
await database.connect()
_log.info("Database Connected")