Skip to content
Advertisement

Discord.py – How to set slash command parameter’s name and description

I’m trying to make discord bot using python discord.py module, and I wanna add slash command with member parameter using CommandTree.

I added parameter but it does not have it’s own parameter name(displays as it’s variable name) and description. How can I add its name and description?

@tree.command(name="send", description="this command sends money to target", guild=discord.Object(guildId))
async def send(interaction, member: discord.Member): # "member" parameter should have description
    # sends money to member

Advertisement

Answer

You can use the app_commands.describe and the app_commands.rename decorators to do this:

Example:

from discord import app_commands

@tree.command(name="send", description="this command sends money to target", guild=discord.Object(guildId))
@app_commands.describe(member="The member to send the money to")
@app_commands.rename(member='whatever_you_want')
async def send(interaction, member: discord.Member):
    # sends money to member

For the description, you could also use docstrings to accomplish your goal:

@tree.command(name="send", guild=discord.Object(guildId))
async def send(interaction, member: discord.Member):
    """This command sends money to a target.

    Parameters
    -----------
    member: discord.Member
        The member to send the money to
    """

discord.py will parse them automatically for you, if you use one of the supported styles.

Docs:

https://discordpy.readthedocs.io/en/latest/interactions/api.html?highlight=describe#discord.app_commands.describe

https://discordpy.readthedocs.io/en/stable/interactions/api.html#discord.app_commands.rename

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement