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/stable/interactions/api.html#discord.app_commands.rename