如何更改discord.py中的帮助命令

时间:2021-01-17 07:31:46

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

我最近发现了以下屏幕截图,我想知道如何在我的 discord bot 中使用 discord.py 获得这种行为。

enter image description here

1 个答案:

答案 0 :(得分:1)

您看到的是来自 customized discord-likeXenon 聊天。此聊天允许您进行类似 Discord 的聊天部分,但模拟 Discord 的行为。 Xenon 是开源的,所以如果您想像他们一样做,只需检查他们的 repositories

如果你想自定义你的机器人的 help 命令,你可以用最近的 discord.py-rewrite 更改来实现。要实现您想要的功能,您需要将 HelpCommandMinimalHelpCommand 子类化,然后将其传递给 bot.help_command

以下代码显示了 MinimalHelpCommand 子类化的标准方法:

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

更多信息,discord.py 文档:https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#help-commands