discord.py rewrite/delete 标准帮助命令

discord.py rewrite/delete standard help command

我想制作自定义 !help 命令,但我必须先禁用标准命令。当我这样做时:

client = commands.Bot(command_prefix='!')
client.remove_command('help')

client = commands.Bot(command_prefix='!', help_command=None)

它仍然显示这条信息: [1]: https://i.stack.imgur.com/Ut9dO.png 谁知道怎么删除?

随着最近对 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

按照上面的代码你会得到你想要实现的行为,但是如果你出于任何原因仍然想禁用默认的帮助命令,现在你可以将 None 传递给 help_command kwarg.

有关详细信息,discord.py 文档: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#help-commands

创建帮助命令的更好方法是使用组。
首先删除默认命令;

client.remove_command("help")

然后使用此方法创建帮助命令:

@client.group(invoke_without_command= True)

async def help(ctx):
    # insert your help command embed or message here
    embed= discord.Embed(title="Help", description="List of commands")
    embed.add_field(name="Moderation", value="!help moderation")
    embed.add_field(name="Misc", value="!help misc")
    await ctx.send(embed=embed)

您已经完成了帮助命令,现在您必须为类别或命令提供帮助。你可以这样做:

@help.command()

async def moderation(ctx):
    embed= discord.Embed(title="Moderation", description="List of Moderation commands")
    embed.add_field(name="Commands", value="ban, kick, warn, mute, unban")
    await ctx.send(embed=embed)

现在,如果用户输入,!help moderation 上面的 embed/message 将被发送。