jarvis-bot/jarvis/cogs/error.py

36 lines
1.2 KiB
Python

from discord.ext import commands
import jarvis
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):
await ctx.send(
"Command does not exist. Run `>help` to get a list of commands"
)
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.")
elif isinstance(error, commands.errors.CommandNotFound):
await ctx.send(
"Command does not exist. Run `>help` to get a list of commands"
)
else:
await ctx.send(f"Error processing command:\n```{error}```")
def setup(bot):
bot.add_cog(ErrorHandlerCog(bot))