45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from discord.ext import commands
|
|
from discord_slash import SlashContext
|
|
|
|
from jarvis import slash
|
|
|
|
|
|
class ErrorHandlerCog(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.Cog.listener()
|
|
async def on_command_error(self, ctx: commands.Context, error):
|
|
if isinstance(error, commands.errors.MissingPermissions):
|
|
await ctx.send("I'm afraid I can't let you do that.")
|
|
elif isinstance(error, commands.errors.CommandNotFound):
|
|
return
|
|
elif isinstance(error, commands.errors.CommandOnCooldown):
|
|
await ctx.send(
|
|
"Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again",
|
|
)
|
|
else:
|
|
await ctx.send(f"Error processing command:\n```{error}```")
|
|
ctx.command.reset_cooldown(ctx)
|
|
|
|
@commands.Cog.listener()
|
|
async def on_slash_command_error(self, ctx: SlashContext, error):
|
|
if isinstance(error, commands.errors.MissingPermissions) or isinstance(error, commands.errors.CheckFailure):
|
|
await ctx.send("I'm afraid I can't let you do that.", hidden=True)
|
|
elif isinstance(error, commands.errors.CommandNotFound):
|
|
return
|
|
elif isinstance(error, commands.errors.CommandOnCooldown):
|
|
await ctx.send(
|
|
"Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again",
|
|
hidden=True,
|
|
)
|
|
else:
|
|
await ctx.send(
|
|
f"Error processing command:\n```{error}```",
|
|
hidden=True,
|
|
)
|
|
slash.commands[ctx.command].reset_cooldown(ctx)
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(ErrorHandlerCog(bot))
|