How to override a supposedly already existing command in discord.py?

Viewed 927

I am rewriting my discord bot to use cogs, and when coding in my "help" command, it stopped compiling. the code is:

@commands.command(name = 'help')
  async def help(self, ctx):
    embedVar = discord.Embed(title="AbidBot Help", description="The command prefix is !.", color=0xffffff)
    embedVar.add_field(name="!inspire", value="Get a random inspirational quote", inline=False)
    embedVar.set_footer(text="More commands are added daily so check this every once in a while")
    await ctx.send(embed=embedVar)

The error that it throws says:

ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: 
Extension 'cogs.cog_general' raised an error: 
CommandRegistrationError: 
The command help is already an existing command or alias.

I have not made a help command, what can I do to remedy this?

2 Answers

Oh this is actually really quite simple, Discord starts with a built in help command, but to disable it you just need to put bot.remove_command("help") at the beginning

The documentations include that the command aliases cannot share the same name, with the inbuilt help command, by default, the help command already has the aliases of "help" in which the code will give that error.

This can be fixed by using the remove_command attribute, then passing the command as it's parameters;

bot.remove_command("help")

Make sure to change bot if you have already defined client as your Client, or then otherwise leave it. This would now remove the command as long as it is provided before the command you are removing

This can be applied to your command like;

bot.remove_command("help")

@commands.command(name = 'help')
  async def help(self, ctx):
    embedVar = discord.Embed(title="AbidBot Help", description="The command prefix is !.", color=0xffffff)
    embedVar.add_field(name="!inspire", value="Get a random inspirational quote", inline=False)
    embedVar.set_footer(text="More commands are added daily so check this every once in a while")
    await ctx.send(embed=embedVar)
Related