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?
JavaScript
x
4
1
@tree.command(name="send", description="this command sends money to target", guild=discord.Object(guildId))
2
async def send(interaction, member: discord.Member): # "member" parameter should have description
3
# sends money to member
4
Advertisement
Answer
You can use the app_commands.describe
and the app_commands.rename
decorators to do this:
Example:
JavaScript
1
8
1
from discord import app_commands
2
3
@tree.command(name="send", description="this command sends money to target", guild=discord.Object(guildId))
4
@app_commands.describe(member="The member to send the money to")
5
@app_commands.rename(member='whatever_you_want')
6
async def send(interaction, member: discord.Member):
7
# sends money to member
8
For the description, you could also use docstrings to accomplish your goal:
JavaScript
1
10
10
1
@tree.command(name="send", guild=discord.Object(guildId))
2
async def send(interaction, member: discord.Member):
3
"""This command sends money to a target.
4
5
Parameters
6
-----------
7
member: discord.Member
8
The member to send the money to
9
"""
10
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