import discord from discord.colour import Color from discord.ext import commands import sys import json import asyncio from typing import Any, Dict, Sequence from discord import Message class Database: def __init__(self): self.loop = asyncio.get_event_loop() 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 self.config = config self.colors: Dict[str, Color] = self.process_colours(config.get("colors", [])) super().__init__( command_prefix=self.prefix_callable, description=self.config["info"].get("description"), case_insensitive=False, fetch_offline_members=False, intents=intents, slash_command_guilds=[227431704426446848], ) async def prefix_callable(self, _, msg: Message): return commands.when_mentioned_or(*self.config["prefixes"])(self, msg) async def load_cogs(self, cog_names: Sequence[str]): for cog in cog_names: try: self.load_extension(cog) print(f"Succesfully loaded extension {cog}.") except Exception as e: print(f"Failed to load extension {cog}.\n\t{e}", file=sys.stderr) async def on_ready(self): print(f"Logged in as: {self.user}") print(f"Version: {discord.__version__}") print( f"Invite: https://discord.com/oauth2/authorize?scope=bot&client_id=257816631072391168&permissions=70642768" ) text = "ck!connect | ck!help" await self.change_presence(activity=discord.Game(text)) await self.load_cogs(self.INITIAL_EXTENSIONS) def process_colours(self, colors: Dict[str, str]) -> Dict[str, Color]: colour_dict: Dict[str, Color] = {} for name, color in colors.items(): colour_dict[name] = Color(int(color, 16)) return colour_dict 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)