@client.tree.command(name='decide', description='Bing will now help you to decide what happens')
@app_commands.describe(choice1 = "What is your 1st choice?")
@app_commands.describe(choice2 = "What is your 2nd choice?")
@app_commands.describe(choice3 = "What is your 3rd choice?")
@app_commands.required(choice3 = False)
@app_commands.describe(choice4 = "What is your 4th choice?")
@app_commands.requiredt(choice3 = False)
@app_commands.describe(choice5 = "What is your 5th choice?")
@app_commands.required(choice3 = False)
async def decide(interaction: discord.Interaction, choice1: str, choice2: str, choice3: str, choice4: str, choice5: str):
print(choice1, choice2, choice3, choice4, choice5)
Discord.py 文档声称有一个“必需”@app_commands 属性用于检查输入是否需要,返回一个错误说它不存在
Traceback (most recent call last):
File "C:\Users\relen\Downloads\BingChatAI.py", line 987, in <module>
@app_commands.required(choice3 = False)
AttributeError: module 'discord.app_commands' has no attribute 'required'
如果您只是希望这些是可选的,您有两种方法
第一:
import typing
@bot.tree.command(name='decide', description='Bing will now help you to decide what happens')
@app_commands.describe(choice1 = "What is your 1st choice?")
@app_commands.describe(choice2 = "What is your 2nd choice?")
@app_commands.describe(choice3 = "What is your 3rd choice?")
@app_commands.describe(choice4 = "What is your 4th choice?")
@app_commands.describe(choice5 = "What is your 5th choice?")
async def decide(interaction: discord.Interaction, choice1: str, choice2: str, choice3:typing.Optional[str], choice4:str,choice5:str):
print(choice1,choice2,choice3,choice4,choice5)
第二:
@bot.tree.command(name='decide2', description='Bing will now help you to decide what happens')
@app_commands.describe(choice1 = "What is your 1st choice?")
@app_commands.describe(choice2 = "What is your 2nd choice?")
@app_commands.describe(choice3 = "What is your 3rd choice?")
@app_commands.describe(choice4 = "What is your 4th choice?")
@app_commands.describe(choice5 = "What is your 5th choice?")
async def decide2(interaction: discord.Interaction, choice1: str, choice2: str, choice4:str,choice5:str,choice3:str=None):
print(choice1,choice2,choice3,choice4,choice5)