commit b17e3c5f28eea45176b297b0625692756d26c4a8 Author: DefsNotQuack Date: Sat Mar 29 10:58:56 2025 +1000 Initial commit. diff --git a/cogs/__init__.py b/cogs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cogs/channel.py b/cogs/channel.py new file mode 100644 index 0000000..36e1a1a --- /dev/null +++ b/cogs/channel.py @@ -0,0 +1,30 @@ +import discord +from discord.ext import commands + +class Channel(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.slash_command(name="clear_channel", + description="Permanently delete all messages in a channel", + guild_ids=[681414775468589180]) + @commands.has_permissions(manage_messages=True) + async def clear_channel(self, ctx: discord.ApplicationContext): + progress = await ctx.respond("Deleting all messages in this channel...", ephemeral=True) + channel = ctx.channel + + # Fetch all messages in the channel + async for message in channel.history(limit=None): + try: + await message.delete() + except discord.Forbidden: + await ctx.send("I do not have permission to delete messages.") + return + except discord.HTTPException: + await ctx.send("Failed to delete a message.") + return + + await progress.edit(content="✔ All messages deleted successfully! ✔") + +def setup(bot): + bot.add_cog(Channel(bot)) \ No newline at end of file diff --git a/cogs/hello.py b/cogs/hello.py new file mode 100644 index 0000000..800c45e --- /dev/null +++ b/cogs/hello.py @@ -0,0 +1,15 @@ +import discord +from discord.ext import commands + +class Hello(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.slash_command(name="hello", + description="Say hi to the bot!", + guild_ids=[681414775468589180]) + async def hello(self, ctx: discord.ApplicationContext): + await ctx.respond("Hello there!") + +def setup(bot): + bot.add_cog(Hello(bot)) \ No newline at end of file diff --git a/cogs/ping.py b/cogs/ping.py new file mode 100644 index 0000000..002d62a --- /dev/null +++ b/cogs/ping.py @@ -0,0 +1,13 @@ +import discord +from discord.ext import commands + +class Ping(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.slash_command(name="ping", description="Ping the bot") + async def ping(self, ctx: discord.ApplicationContext): + await ctx.respond("🏓 Pong!") + +def setup(bot): + bot.add_cog(Ping(bot)) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..72abd27 --- /dev/null +++ b/main.py @@ -0,0 +1,75 @@ +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()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0e5cc08 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +dotenv~=0.9.9 +python-dotenv~=1.1.0 +rich~=13.9.4 +py-cord~=2.6.1 \ No newline at end of file