From 4a2cc0e62bb5940680c5034f3543528982630fa4 Mon Sep 17 00:00:00 2001 From: strNophix Date: Sun, 31 Oct 2021 11:23:54 +0100 Subject: [PATCH] A bunch of small changes --- bot.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/bot.py b/bot.py index 061daec..3b0a779 100644 --- a/bot.py +++ b/bot.py @@ -3,32 +3,24 @@ from discord.colour import Color from discord.ext import commands import sys import json -import asyncio -from typing import Any, Dict, Sequence +from typing import Any, Dict, List, Sequence from discord import Message - - -class Database: - def __init__(self): - self.loop = asyncio.get_event_loop() +from discord.ext.commands.errors import ( + ExtensionAlreadyLoaded, + ExtensionFailed, + ExtensionNotFound, + NoEntryPointError, +) class ChristmasBot(commands.Bot): - INITIAL_EXTENSIONS = [ - "cogs.owner", - "cogs.settings", - "cogs.information", - "cogs.music", - ] - def __init__(self, config: Dict[Any, Any]): - intents: discord.Intents = discord.Intents.none() - intents.voice_states = True - intents.guild_messages = True - intents.guilds = True - intents.messages = True + intents = discord.Intents( + voice_states=True, guild_messages=True, guilds=True, messages=True + ) self.config = config + self.initial_cog_names: List[str] = self.config.get("cogs", []) self.colors: Dict[str, Color] = self.process_colours(config.get("colors", [])) self.invite_link: str = "" @@ -56,7 +48,12 @@ class ChristmasBot(commands.Bot): try: self.load_extension(cog) print(f"Succesfully loaded extension {cog}.") - except Exception as e: + except ( + ExtensionNotFound, + ExtensionAlreadyLoaded, + NoEntryPointError, + ExtensionFailed, + ) as e: print(f"Failed to load extension {cog}.\n\t{e}", file=sys.stderr) async def on_ready(self): @@ -84,5 +81,4 @@ if __name__ == "__main__": config = json.load(open("config.json", "r", encoding="utf-8")) token = config.pop("token") - bot = ChristmasBot(config) - bot.run(token, reconnect=True) + ChristmasBot(config).run(token, reconnect=True)