Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
737 views
in Technique[技术] by (71.8m points)

python - Discord.py - change the default help command

I'm trying to change the help command to use a pagination version of help.

I understand that the following line of code removes the help command entirely:

bot.remove_command('help')

The docs/dicord.py server offer the following example as a way to change the default help command:

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

I'm still a newbie in python, and I've only been learning rewrite for about 3 days - I'm struggling to find any working examples or an explanation that doesn't lead me back to the above code. I can't work out how to implement this into my own code - so my question is, could anyone provide further explaination into how this would be implemented using cogs?

question from:https://stackoverflow.com/questions/65875925/programming-a-discord-bot-in-python-how-do-i-modify-the-default-help-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use help_command=None. It delete default help command and you can create your help command. Example:

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

@bot.command()
async def help(context):
    await context.send("Custom help command")

If you don't set help_command=None and try to create your help command, you get this error: discord.errors.ClientException: Command help is already registered.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...