首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向Slash命令中添加条件字段

向Slash命令中添加条件字段
EN

Stack Overflow用户
提问于 2022-08-19 11:17:08
回答 1查看 89关注 0票数 1

如何添加一些字段,以显示用户是否从discord.Option()列表中选择了一个选项?我的意思是,如果用户选择‘选项a1’,他/她将看到字段'a1‘,如果他选择’选项b2‘,他/她将看到字段'a2’。这是我的选项列表代码:

代码语言:javascript
复制
@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“字段。

EN

回答 1

Stack Overflow用户

发布于 2022-08-24 10:52:50

首先,您不应该在装饰器后面缩进函数。然后,要为您的mode参数创建选择,您可以像以前一样使用arg choices,这是一个list

在这个列表中,应该有discord.OptionChoice()类。

在你的情况下,你会得到:

代码语言:javascript
复制
@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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73415958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档