【问题标题】:How to remove or change the default help command?如何删除或更改默认帮助命令?
【发布时间】:2018-02-07 15:00:50
【问题描述】:

如何删除或至少更改 discord.py 中默认帮助命令的格式?

我认为更改格式会很好,我根本不喜欢这种格式。

【问题讨论】:

标签: python discord.py


【解决方案1】:

试试这个:

bot.remove_command('help')

将其放在代码顶部,在导入之后。 然后创建你自己的。

或者要对其进行格式化,请查看:Click here!

【讨论】:

  • 请编辑您的帖子以更具体。您链接到源代码中的一个文件,但您没有说明如何处理它。
【解决方案2】:

根据docs禁用帮助命令的正确方法是将help_command=None传递给discord.ext.commands.Bot的构造函数,例如:

bot = commands.Bot(help_command=None)

class MyBot(commands.Bot):
    def __init__(self):
        super().__init__(help_command=None)

这也让您有机会将自己的帮助函数传递到 help_command 参数中以实现不同的格式。

【讨论】:

    【解决方案3】:

    例如,您将需要删除该命令

    client.remove_command('help')
    

    你需要把它放在下面

    client = commands.Bot
    

    会是这样的

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

    【讨论】:

      【解决方案4】:

      你可以在这里使用:

      intents = discord.Intents.all()
      
      activity = discord.Game(name=f"!help in {len(client.guilds)} servers!")
      
      client = commands.Bot(command_prefix="!", intents=intents, activity=activity, status=discord.Status.do_not_disturb, help_command=None)
      

      【讨论】:

        【解决方案5】:

        这是你应该这样做的,以便它保留帮助命令的行为,同时让你改变它的外观:

        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```
        

        有关详细信息,请参阅文档:https://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#help-commands

        对于从旧的帮助格式化程序迁移:https://discordpy.readthedocs.io/en/rewrite/migrating.html#helpformatter-and-help-command-changes

        【讨论】:

        • 特别有趣,因为我找不到任何关于自动生成消息中预期语法的文档。
        【解决方案6】:

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

        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()```
        The built in help command is of great use
        

        【讨论】:

          猜你喜欢
          • 2020-10-19
          • 1970-01-01
          • 2018-08-15
          • 2021-04-21
          • 2020-07-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-04-17
          相关资源
          最近更新 更多