Как сделать выбор действия в слеш командах discord.py?
Увидел в чьёмто боте реализован выбор варианта, т.е участник при вводе аргументов видет что что-то вылезло, и выберает то что ему нужно, возможно ли это реализовать?
Ответы (1 шт):
Автор решения: quswadress
→ Ссылка
Да, возможно. Вы можете использовать discord.app_commands.describe() для описания аргументов, а если аргумент не обязателен можно в функции задать аргументу значение по умолчанию.
# Пример команды с обязательными аргументами
@client.tree.command()
@app_commands.describe(
first_value='The first value you want to add something to',
second_value='The value you want to add to the first value',
)
async def add(interaction: discord.Interaction, first_value: int, second_value: int):
"""Adds two numbers together."""
await interaction.response.send_message(f'{first_value} + {second_value}'
f'= {first_value + second_value}')
# Пример команды с необязательными аргументами
# 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()
@app_commands.describe(member='The member you want to get the joined date from;'
'defaults to the user who uses the command')
async def joined(interaction: discord.Interaction, member: Optional[discord.Member] = None):
"""Says when a member joined."""
# If no member is explicitly provided then we use the command user here
member = member or interaction.user
# The format_dt function formats the date time into
# a human readable representation in the official client
await interaction.response.send_message(f'{member} joined '
f'{discord.utils.format_dt(member.joined_at)}')
Советую вам полностью прочитать оригинал кода который находится здесь и лицензирован под лицензией MIT, текст которой находится здесь.
Ниже находится само выполнение команды в клиенте Discord-а.

И с обязательными аргументами:
