Experto
Experto

Reputation: 25

Use multiple cooldowns discord.py

I've been trying to use multiple cooldowns (for invalid commands and command cooldowns), but I get Redefinition of usage for both of the on_command_error events.

This is what I have currently:

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        myEmbed1000 = discord.Embed(description=f":x: {random.choice(silly_e)} {ctx.author.name}, that is not a vaild command!", color=0xDD2E44)

        await ctx.reply(embed=myEmbed1000)

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        cooldownem = discord.Embed(description=f"{random.choice(silly_e)} **{ctx.author.name}**, please wait after {round(error.retry_after)} second(s)!", color=0xfae93a)

        await ctx.reply(embed=cooldownem)

Upvotes: 0

Views: 53

Answers (1)

RiveN
RiveN

Reputation: 2663

You can't use two on_command_error events. If you want to catch multiple errors (cooldown, invalid command, etc.). You should only use one event and create multiple if/elif statements:

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        myEmbed1000 = discord.Embed(description=f":x: {random.choice(silly_e)} {ctx.author.name}, that is not a vaild command!", color=0xDD2E44)
        await ctx.reply(embed=myEmbed1000)

    elif isinstance(error, commands.CommandOnCooldown):
        cooldownem = discord.Embed(description=f"{random.choice(silly_e)} **{ctx.author.name}**, please wait after {round(error.retry_after)} second(s)!", color=0xfae93a)
        await ctx.reply(embed=cooldownem)

Upvotes: 1

Related Questions