import os import discord import asyncio from dotenv import load_dotenv from pathlib import Path from rich.console import Console from rich.progress import track from rich.panel import Panel load_dotenv() TOKEN = os.getenv("BOT_TOKEN") DEV_GUILD_ID = int(os.getenv("DEV_GUILD_ID")) # Initialize the console for rich output console = Console() # Set up intents for the bot intents = discord.Intents.default() intents.message_content = True # Create the bot instance bot = discord.Bot(intents=intents) # Cog directory and Loading handling COG_PATH = Path(__file__).resolve().parent / "cogs" cogs_available = {} loaded_cog_modules = {} for file in COG_PATH.iterdir(): if file.suffix == ".py" and not file.name.startswith("__"): cog_name = file.stem cogs_available[cog_name] = file async def load_cogs(): if not cogs_available: console.log("[yellow]⚙️ No cogs available to load...[/yellow]") return if not COG_PATH.exists(): console.log(f"[red]❌ Cogs directory not found at {COG_PATH}[/red]") return console.print(Panel.fit("🔌 [bold]Loading Cogs[/bold]", style="cyan")) for cog in track(cogs_available, description="Loading Cogs..."): module_path = f"cogs.{cog}" try: bot.load_extension(module_path) loaded_cog_modules[cog] = module_path console.log(f"[green]✔ Loaded:[/] Cog - {cog}") except Exception as e: console.log(f"[red]✖ Failed to load:[/] Cog - {cog}") console.log(f"[red]{type(e).__name__}: {e}[/]") # Bot Event Handlers @bot.event async def on_ready(): await load_cogs() await bot.sync_commands() console.log("[blue]🔁 Synced slash commands[/blue]") console.rule(f"[bold green]✅ Bot Ready — Logged in as {bot.user}[/]") console.print(f"ID: {bot.user.id}") # Main Loop if __name__ == "__main__": async def main(): # Load cogs before the bot starts #await load_cogs() # Start the bot await bot.start(TOKEN) # Run the main loop asyncio.run(main())