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 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 else: await ctx.send( f"Error processing command:\n```{error}```", hidden=True ) def setup(bot): bot.add_cog(ErrorHandlerCog(bot))