【问题标题】:How can I check if a command is in a group in discord.py?如何检查命令是否在 discord.py 中的组中?
【发布时间】:2021-06-10 12:15:10
【问题描述】:

我有一个帮助命令,它使用以下循环来查找给定 cog 中的所有命令。

for command in self.bot.get_cog(cog).walk_commands():
    if not command.hidden:
        emb.add_field(name=f"`{command.name}`", value=command.help, inline=False)

这不区分哪些命令是子命令(group 的命令)。 我想要的是一种方法来区分哪些命令是组,哪些(子)命令属于哪个组。

Example 我不想要的东西(这是当前行为)。

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    您可以使用commandparent 属性,如果没有group,它将返回groupNone。示例:

    for command in self.bot.get_cog(cog).walk_commands():
        print(f"`{command.name}` `{command.parent}`")
    

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 1970-01-01
      • 2015-04-07
      • 2021-11-05
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2016-10-20
      • 2012-09-21
      相关资源
      最近更新 更多