Add an example for app_commands.rename()

Co-authored-by: Danny <Rapptz@users.noreply.github.com>
This commit is contained in:
Narmy 2022-05-01 00:45:17 +02:00 committed by GitHub
parent 61105ce925
commit 8e9e25246e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,6 +57,17 @@ async def add(interaction: discord.Interaction, first_value: int, second_value:
await interaction.response.send_message(f'{first_value} + {second_value} = {first_value + second_value}')
# The rename decorator allows us to change the display of the parameter on Discord.
# In this example, even though we use `text_to_send` in the code, the client will use `text` instead.
# Note that other decorators will still refer to it as `text_to_send` in the code.
@client.tree.command()
@app_commands.rename(text_to_send='text')
@app_commands.describe(text_to_send='Text to send in the current channel')
async def send(interaction: discord.Interaction, text_to_send: str):
"""Sends the text into the current channel."""
await interaction.response.send_message(text_to_send)
# To make an argument optional, you can either give it a supported default argument
# or you can mark it as Optional from the typing standard library. This example does both.
@client.tree.command()