Reset cooldown on unintended error

This commit is contained in:
Zeva Rose 2021-08-03 18:30:26 -06:00
parent a3228280f6
commit 155ca221fa

View file

@ -1,4 +1,5 @@
from discord.ext import commands from discord.ext import commands
from discord_slash import SlashContext
class ErrorHandlerCog(commands.Cog): class ErrorHandlerCog(commands.Cog):
@ -6,20 +7,22 @@ class ErrorHandlerCog(commands.Cog):
self.bot = bot self.bot = bot
@commands.Cog.listener() @commands.Cog.listener()
async def on_command_error(self, ctx, error): async def on_command_error(self, ctx: commands.Context, error):
if isinstance(error, commands.errors.MissingPermissions): if isinstance(error, commands.errors.MissingPermissions):
await ctx.send("I'm afraid I can't let you do that.") await ctx.send("I'm afraid I can't let you do that.")
elif isinstance(error, commands.errors.CommandNotFound): elif isinstance(error, commands.errors.CommandNotFound):
return return
elif isinstance(error, commands.errors.CommandOnCooldown): elif isinstance(error, commands.errors.CommandOnCooldown):
await ctx.send( await ctx.send(
"Command on cooldown. Please wait before trying again", "Command on cooldown. "
+ f"Please wait {error.retry_after:0.2f}s before trying again",
) )
else: else:
await ctx.send(f"Error processing command:\n```{error}```") await ctx.send(f"Error processing command:\n```{error}```")
ctx.command.reset_cooldown(ctx)
@commands.Cog.listener() @commands.Cog.listener()
async def on_slash_command_error(self, ctx, error): async def on_slash_command_error(self, ctx: SlashContext, error):
if isinstance(error, commands.errors.MissingPermissions) or isinstance( if isinstance(error, commands.errors.MissingPermissions) or isinstance(
error, commands.errors.CheckFailure error, commands.errors.CheckFailure
): ):
@ -37,6 +40,7 @@ class ErrorHandlerCog(commands.Cog):
f"Error processing command:\n```{error}```", f"Error processing command:\n```{error}```",
hidden=True, hidden=True,
) )
ctx.command.reset_cooldown(ctx)
def setup(bot): def setup(bot):