1

How do I add multiple commands with the same name in Discord.py? For example:

@client.command(aliases=["dices"])
async def dice(ctx, num):
  try:
    num=int(num)
    bla bla bla
  except ValueError:
    await ctx.send("Invalid Number!")

@client.command(name='dice',aliases=["dices"])
async def dice_no_param(ctx):
  try:
      roll = random.randint(1,6)
      bla bla bla
  except ValueError:
    await ctx.send("Invalid Number!")

But obviously, I get an error.

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import bot
  File "/home/runner/HamburgerBot/bot.py", line 147, in <module>
    async def dice_no_param(ctx):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1163, in decorator
    self.add_command(result)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1071, in add_command
    raise discord.ClientException('Command {0.name} is already registered.'.format(command))
discord.errors.ClientException: Command dice is already registered.

2 Answers 2

3

You can't but for your dice command purpose you can do it like this

@client.command(name='dice', aliases=['dices'])
async def dice(ctx, num=None):
    num = num or random.randint(1, 6)
    try:
        num = int(num)
    except ValueError:
        return await ctx.send("Invalid Number!")
    # bla bla bla other code
Sign up to request clarification or add additional context in comments.

Comments

2

In first line, write the name of the function you used for the command with. It must should write like this-

@client.command(name='Name_of_the_function', aliases=['what_command_you_also_want_to_use'])

You can use multiple commands like this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.