【问题标题】:Discord.py - change the default help commandDiscord.py - 更改默认帮助命令
【发布时间】:2020-10-19 23:23:22
【问题描述】:

我正在尝试更改帮助命令以使用分页版本的帮助。

我了解以下代码行完全删除了帮助命令:

bot.remove_command('help')

docs/dicord.py 服务器提供以下示例来更改默认帮助命令:

class MyHelpCommand(commands.MinimalHelpCommand):
    def get_command_signature(self, command):
        return '{0.clean_prefix}{1.qualified_name} {1.signature}'.format(self, command)

class MyCog(commands.Cog):
    def __init__(self, bot):
        self._original_help_command = bot.help_command
        bot.help_command = MyHelpCommand()
        bot.help_command.cog = self

    def cog_unload(self):
        self.bot.help_command = self._original_help_command

我仍然是 python 的新手,我只学习了大约 3 天的重写 - 我正在努力寻找任何不会让我回到上述代码的工作示例或解释。我不知道如何在我自己的代码中实现它 - 所以我的问题是,谁能提供进一步解释如何使用 cogs 实现它?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您可以使用help_command=None。它删除默认帮助命令,您可以创建帮助命令。示例:

    bot = commands.Bot(command_prefix='!', help_command=None)
    
    @bot.command()
    async def help(context):
        await context.send("Custom help command")
    

    如果您没有设置 help_command=None 并尝试创建帮助命令,则会收到此错误:discord.errors.ClientException: Command help is already registered

    【讨论】:

      【解决方案2】:

      你真的不需要删除命令...这不好,使用(前缀)帮助命令名

      class NewHelpName(commands.MinimalHelpCommand):
          async def send_pages(self):
              destination = self.get_destination()
              for page in self.paginator.pages:
                  emby = discord.Embed(description=page)
                  await destination.send(embed=emby)
      client.help_command = NewHelpName()
      

      内置的帮助命令很有用

      【讨论】:

      • 你能在这个答案中添加一些细节吗?就像一个关于如何在这个用例中使用它的例子?这提高了这个答案的可重用性。
      猜你喜欢
      • 2021-04-21
      • 2018-02-07
      • 2020-11-06
      • 2021-09-16
      • 2018-08-15
      • 2021-01-01
      • 2019-03-17
      • 2019-07-16
      • 1970-01-01
      相关资源
      最近更新 更多