43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from discord.ext import commands
|
|
|
|
|
|
class ErrorHandlerCog(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.Cog.listener()
|
|
async def on_command_error(self, ctx, 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. Please wait before trying again",
|
|
hidden=True,
|
|
)
|
|
else:
|
|
await ctx.send(f"Error processing command:\n```{error}```")
|
|
|
|
@commands.Cog.listener()
|
|
async def on_slash_command_error(self, ctx, 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. Please wait before trying again",
|
|
hidden=True,
|
|
)
|
|
else:
|
|
await ctx.send(
|
|
f"Error processing command:\n```{error}```",
|
|
hidden=True,
|
|
)
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(ErrorHandlerCog(bot))
|