discord.py – already an existing command or an alias for no reason repeatedly

This is my code


import discord
from discord.ext import commands

for filename in os.listdir('./cogs'):
  if filename.endswith('.py'):

async def on_message(message):
  if client.user == message.author:
# The message logging command comes here
  await client.process_commands(message)



import discord
from discord.ext import commands
from json import load as loadjson

class BotGeneralCommands(commands.Cog):
    def __init__(self, client: commands.Bot):
        self.client = client

        self.botconfigdata = loadjson(open("config.json", "r"))
        self.bot_inv_link = self.botconfigdata["invite-link"]

    @commands.command(aliases=["invite", "botlink", "invitelink"])
    async def invite(self, ctx):
        await ctx.send("```Hey there! Make sure you have me in your server too! Bot Invite link:```" + str(self.bot_inv_link))

def setup(client: commands.Bot):


Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 618, in _load_from_module_spec
  File "/home/runner/Main-Discord-Bot-of-ZeaCeR5641/cogs/botinfo.py", line 79, in setup
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 507, in add_cog
    cog = cog._inject(self)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/cog.py", line 413, in _inject
    raise e
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/cog.py", line 407, in _inject
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1155, in add_command
    raise CommandRegistrationError(alias, alias_conflict=True)
discord.ext.commands.errors.CommandRegistrationError: The alias invite is already an existing command or alias.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 523, in <module>
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 678, in load_extension
    self._load_from_module_spec(spec, name)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 623, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e

discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.botinfo' raised an error: CommandRegistrationError: The alias invite is already an existing command or alias.

I literally checked on every other cog for this discord bot and this command (invite exists only here…). Why do i keep getting this error?

What i have done: I commented out that piece of code, started the bot again and it gave me the same error, but the command name being different, I commented the all shown commands for 11 times ( even though they were only defined in one place ). But i keep getting that error!

This bot has over 240 commands and does it have anything to do with issue?

What can i do?


Discord.py takes function names as command names when you use @commands.command without the name kwarg. So since you have:

@commands.command(aliases=["invite", "botlink", "invitelink"])
async def invite(self, ctx):

The invite alias is added, and then the discord.py library tries to add invite as a command name since it’s the name of the function. You can simply remove invite as an alias to fix the problem:

@commands.command(aliases=["botlink", "invitelink"])
async def invite(self, ctx):