如何添加一些字段,以显示用户是否从discord.Option()列表中选择了一个选项?我的意思是,如果用户选择‘选项a1’,他/她将看到字段'a1‘,如果他选择’选项b2‘,他/她将看到字段'a2’。这是我的选项列表代码:
@warn_command_group.command(name='remove',description='حذف اخطار')
async def remove_warn(self, ctx:discord.ApplicationContext,
mode:discord.Option(str,'حالت حذف',choices=[
'حذف کل اخطار های سرور', # delete all warns
'حذف کل اخطار های یک ممبر', # delete all warns from a member
'حذف یک اخظار خاص(با استفاده از آیدی اون اخطار)' # delete a specific warn (with that warn's id)
])
):我的意思是,如果他们选择第一个选项,他们将不会看到任何强制字段,如果他们选择第二个选项,他们将看到一个名为“discord.Member”类型的字段,如果他们选择第三个选项,他们将看到一个带有int类型的"id“字段。
发布于 2022-08-24 10:52:50
首先,您不应该在装饰器后面缩进函数。然后,要为您的mode参数创建选择,您可以像以前一样使用arg choices,这是一个list。
在这个列表中,应该有discord.OptionChoice()类。
在你的情况下,你会得到:
@warn_command_group.command(name='remove',description='حذف اخطار')
async def remove_warn(self, ctx:discord.ApplicationContext,
mode:discord.Option(str,'حالت حذف', required=True, choices=[
discord.OptionChoice(name='حذف کل اخطار های سرور', value="deleteAll"),
discord.OptionChoice(name='حذف کل اخطار های یک ممبر', value="deleteMemberAll"),
discord.OptionChoice(name='حذف یک اخظار خاص(با استفاده از آیدی اون اخطار)', value="deleteWarn")
])
):
if mode == "deleteAll":
#Some stuff if the user has selected the first choice
elif mode == "deleteMemberAll":
#Some stuff is the user has selected the second choice
else:
#Some stuff is the user has selected the third choice请参阅https://docs.pycord.dev/en/master/api.html?highlight=discord%20option#discord.Option.choices
https://stackoverflow.com/questions/73415958
复制相似问题