branhoff / hooter-the-tutor

0 stars 2 forks source link

Refactor bot structure to use Discord.py cogs #8

Closed branhoff closed 3 months ago

branhoff commented 3 months ago

Refactor bot structure to use Discord.py cogs

Description

Currently, our bot's commands and functionality are centralized in a single commands.py file. To improve modularity, maintainability, and scalability, we should refactor our bot structure to use Discord.py cogs.

Objectives

Tasks

Implementation Details

  1. Each cog should be a subclass of commands.Cog
  2. Include a setup function in each cog file for easy loading
  3. Use the bot.load_extension() method in the main file to load cogs

Example Cog Structure

from discord.ext import commands

class ExampleCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def example_command(self, ctx):
        await ctx.send("This is an example command in a cog!")

def setup(bot):
    bot.add_cog(ExampleCog(bot))
branhoff commented 3 months ago

Cogs evidently also include listeners which I'm calling "events" in my code. For now, I think I'm just intending to encapsulate the command logic into cogs.

https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html