0
votes

I'm just trying out with making Discord bots and I tried putting this command in a category, however, this error shows up no matter what I call the command. Here's my code:

import discord,random
from discord.ext import commands 

bot = commands.Bot(command_prefix=';')

@bot.event
async def on_ready():
    print("bot is ready for stuff")
    await bot.change_presence(activity=discord.Game(name=";help"))

class general_stuff(commands.Cog):
    """Stuff that's not important to the bot per say"""

    @bot.command()
    async def lkibashfjiabfiapbfaipb(self, message):
        await message.send("test received.")

bot.add_cog(general_stuff())
bot.run("TOKEN")

and this is the error I get back:

The command lkibashfjiabfiapbfaipb is already an existing command or alias.

No matter how much I change the command, it keeps giving the same error.

1

1 Answers

0
votes

You are on the right track. The reason you are getting the error is when you start the program, it reads from the top and works its way down;

class general_stuff(commands.Cog):
    """Stuff that's not important to the bot per se"""

    @bot.command() # Command is already registered here
    async def lkibashfjiabfiapbf(self, message):
        await message.send("test received.")

bot.add_cog(general_stuff()) 
# It tries to load the class general_stuff, but gets the error because
# it's trying to load the same command as it loaded before

@bot.command adds the method to the bot and loads it. With Cogs, you operate with @commands.command(). It only converts the method to a command, but does not load it in.

Your code should look like

...
class general_stuff(commands.Cog):
    """Stuff that's not important to the bot per se"""

    @commands.command()
    async def lkibashfjiabfiapbf(self, message):
        await message.send("test received.")
...

References: