Discord.py更改默认的帮助命令

2024-06-01 22:23:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将help命令更改为使用分页版本的help

我知道以下代码行完全删除了help命令:

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实现这一点吗


Tags: 代码命令self版本示例defbothelp
2条回答

您实际上不需要删除该命令。。。使用(前缀)help命令名<;,这不好那就不会出现了。。。如果你想要它,你可以做

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()

内置的help命令非常有用

您可以使用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

相关问题 更多 >