async def on_command_error(self, context, exception): if isinstance(exception, commands.BadUnionArgument): msg = "Could not find the specified " + human_join( [c.__name__ for c in exception.converters]) await context.trigger_typing() await context.send( embed=discord.Embed(color=discord.Color.red(), description=msg) ) elif isinstance(exception, commands.BadArgument): await context.trigger_typing() await context.send(embed=discord.Embed(color=discord.Color.red(), description=str(exception))) elif isinstance(exception, commands.CommandNotFound): logger.warning(error("CommandNotFound: " + str(exception))) elif isinstance(exception, commands.MissingRequiredArgument): await context.send_help(context.command) elif isinstance(exception, commands.CheckFailure): for check in context.command.checks: if not await check(context) and hasattr(check, "fail_msg"): await context.send(embed=discord.Embed( color=discord.Color.red(), description=check.fail_msg)) logger.warning(error("CheckFailure: " + str(exception))) else: logger.error(error("Unexpected exception:"), exc_info=exception)
async def on_command_error(self, context, exception): if isinstance(exception, commands.BadUnionArgument): msg = "Could not find the specified " + human_join( [c.__name__ for c in exception.converters]) await context.trigger_typing() await context.send( embed=discord.Embed(color=self.error_color, description=msg)) elif isinstance(exception, commands.BadArgument): await context.trigger_typing() await context.send(embed=discord.Embed(color=self.error_color, description=str(exception))) elif isinstance(exception, commands.CommandNotFound): logger.warning("CommandNotFound: %s", exception) elif isinstance(exception, commands.MissingRequiredArgument): await context.send_help(context.command) elif isinstance(exception, commands.CheckFailure): for check in context.command.checks: if not await check(context): if hasattr(check, "fail_msg"): await context.send(embed=discord.Embed( color=self.error_color, description=check.fail_msg) ) if hasattr(check, "permission_level"): corrected_permission_level = self.command_perm( context.command.qualified_name) logger.warning( "User %s does not have permission to use this command: `%s` (%s).", context.author.name, context.command.qualified_name, corrected_permission_level.name, ) logger.warning("CheckFailure: %s", exception) else: logger.error("Unexpected exception:", exc_info=exception)