-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
49 lines (41 loc) · 1.5 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
"""
Created by Epic at 10/13/20
"""
from config import BOT_TOKEN, DEFAULT_PREFIX
from colorformat import basicConfig
from discord.ext.commands import Bot as BaseBot, MinimalHelpCommand
from discord import Intents, Message
from pathlib import Path
from logging import getLogger, DEBUG
class Bot(BaseBot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.help_command = MinimalHelpCommand()
self.logger = getLogger("AQue")
self.logger.setLevel(DEBUG)
basicConfig(self.logger)
self.load_extension("jishaku")
self.load_cogs()
def load_cogs(self):
cogs_dir = Path("./cogs/")
for cog in cogs_dir.glob("*.py"):
cog_name = "cogs." + str(cog).split("/")[-1][:-3]
try:
self.unload_extension(cog_name)
except:
pass
try:
self.load_extension(cog_name)
self.logger.debug(f"Loaded cog {cog_name}")
except Exception as e:
self.logger.error("A error occurred while loading a cog", exc_info=e)
def get_prefix(_bot: Bot, message: Message):
api = _bot.get_cog("Api")
guild_config = api.get_server_settings(message.guild)
if guild_config is None:
return DEFAULT_PREFIX
return guild_config.get("prefix", DEFAULT_PREFIX)
intents = Intents(guilds=True, voice_states=True, messages=True)
if __name__ == "__main__":
bot = Bot(get_prefix, intents=intents)
bot.run(BOT_TOKEN)