Getting errors in loading a command in discord.py

Question:

So I am building a bot.
Here is the code:

import discord
from discord.ext import commands
from discord.utils import get
client = discord.Client()
bot = commands.Bot(command_prefix="&")
token = "<token censored for privacy>"

@client.event
async def on_ready():
    print(f"{client.user} has connected to Discord.")

@bot.command()
async def repeat(ctx, args):
    await ctx.send(args*10)
    await ctx.send("You got rolled. Do it again.")

bot.add_command(repeat)
client.run(token)

But when I run the code, I get back an error:
discord.ext.commands.errors.CommandRegistrationError: The command repeat is already an existing command or alias.

I have not called the bot.add_command function before. Can anyone help out with this?
Screenshot of the error:
discord.ext.commands.errors.CommandRegistrationError image

Screenshot of the code:
bot.py file

Asked By: beackers

||

Answers:

When you want to add a command to your bot, you have two options.

  • You can add the @bot.command() decorator, or
  • You can use the @commands.command() decorator and run bot.add_command(repeat)

Both of these will add your command to the bot. Take a look at the discord.py documentation for commands for more details about adding commands.

The reason you’re seeing the error is that you actually are adding the command twice.

Answered By: TheBiggerFish
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.