向斜杠命令添加条件字段



如果用户从discord中选择了一个选项,我如何添加一些将显示的字段。选项((列表?我的意思是,如果用户选择"选项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)
])
):

我的意思是,如果他们选择第一个选项,他们将不会看到任何强制场如果他们选择第二个选项;成员";与类型的不和。成员如果他们选择第三个选项;id";具有int 类型

首先,不应该在decorator之后缩进函数。然后,要为mode参数创建选项,可以像以前一样使用参数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

最新更新