【发布时间】:2018-02-07 15:00:50
【问题描述】:
如何删除或至少更改 discord.py 中默认帮助命令的格式?
我认为更改格式会很好,我根本不喜欢这种格式。
【问题讨论】:
-
请先看这个how-to-ask
标签: python discord.py
如何删除或至少更改 discord.py 中默认帮助命令的格式?
我认为更改格式会很好,我根本不喜欢这种格式。
【问题讨论】:
标签: python discord.py
【讨论】:
根据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 参数中以实现不同的格式。
【讨论】:
例如,您将需要删除该命令
client.remove_command('help')
你需要把它放在下面
client = commands.Bot
会是这样的
client = commands.Bot(command_prefix = 'somethingelse')
client.remove_command('help')
【讨论】:
你可以在这里使用:
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)
【讨论】:
这是你应该这样做的,以便它保留帮助命令的行为,同时让你改变它的外观:
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
【讨论】:
你真的不需要删除命令...这不好,使用(前缀)帮助命令名
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
【讨论】: