Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To turn a cog into a command group with a prefix, the following steps can be taken:

  1. Add a prefix variable to your cog class. For example:
class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.prefix = "!"

    ...
  1. Define a command group within the cog using the @commands.group decorator. For example:
class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.prefix = "!"

    @commands.group(name="mycommandgroup")
    async def my_command_group(self, ctx):
        pass

    ...
  1. Define commands within the command group using the @mycommandgroup.command decorator. For example:
class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.prefix = "!"

    @commands.group(name="mycommandgroup")
    async def my_command_group(self, ctx):
        pass

    @my_command_group.command(name="mycommand")
    async def my_command(self, ctx):
        pass

    ...
  1. Add the cog to the bot using the add_cog method. For example:
bot = commands.Bot(command_prefix="!")
bot.add_cog(MyCog(bot))

Now, users can use commands within the command group by typing the prefix followed by the command group name and the command name. For example: "!mycommandgroup mycommand".