Search code examples
pythondiscorddiscord.pybots

How to code group application commands on discord.py


I've been searching for how to group application (interaction) commands for awhile and I haven't found any solution.

I want that when I use "/say" on Discord bot, it shows two options "/say message" and "/say embed", but I haven't found any solutions yet.

Does anyone know what I should do?

I can't seem to understand the discord.py documentation.


Solution

  • a simple way, at least for me, is to make the class name the word you want then add the slash commands.

    example:

    import discord
    from discord.ext import commands
    from discord import app_commands
    
    class say(commands.GroupCog):
        def __init__(self, client: commands.Bot):
            self.client = client (client or bot depending on which you use)
    
    
    
        @app_commands.command(name="message")
        async def message()
          .....
    
        @app_commands.command(name="embed")
        async def embed()
          ....
    
    

    in the example i use @app_commands since i pulled the example from a different file from my main python file.

    basically any command you have under a groupcog will automatically take the name of the cog followed by the command name.