aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-16 18:09:08 -0800
committerGravatar MarkKoz <[email protected]>2020-02-16 18:09:08 -0800
commit9bfdf7e3e95c07a1b0369c9fa8bdb4c91339732f (patch)
tree9a80691bc6429f44f090641256399b64c884dcbf
parentError handler: (almost) always log the error being handled (diff)
Error handler: simplify check failure handler & handle bot missing roles
discord.py's default error messages are quite descriptive already so there really isn't a need to write our own. Therefore, the log calls were removed so that the generic debug log message is used in the on_command_error. In addition to handling missing bot permissions, missing bot roles are also handled. The message doesn't specify which because it doesn't really matter to the end-user. The logs will use the default error messages as described above, and those will contain the specific roles or permissions that are missing.
-rw-r--r--bot/cogs/error_handler.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/bot/cogs/error_handler.py b/bot/cogs/error_handler.py
index ff8b36ddc..6c4074e3a 100644
--- a/bot/cogs/error_handler.py
+++ b/bot/cogs/error_handler.py
@@ -136,21 +136,17 @@ class ErrorHandler(Cog):
@staticmethod
async def handle_check_failure(ctx: Context, e: errors.CheckFailure) -> None:
"""Handle CheckFailure exceptions and its children."""
- command = ctx.command
+ bot_missing_errors = (
+ errors.BotMissingPermissions,
+ errors.BotMissingRole,
+ errors.BotMissingAnyRole
+ )
- if isinstance(e, errors.NoPrivateMessage):
- await ctx.send("Sorry, this command can't be used in a private message!")
- elif isinstance(e, errors.BotMissingPermissions):
- await ctx.send(f"Sorry, it looks like I don't have the permissions I need to do that.")
- log.warning(
- f"The bot is missing permissions to execute command {command}: {e.missing_perms}"
- )
- elif isinstance(e, errors.MissingPermissions):
- log.debug(
- f"{ctx.message.author} is missing permissions to invoke command {command}: "
- f"{e.missing_perms}"
+ if isinstance(e, bot_missing_errors):
+ await ctx.send(
+ f"Sorry, it looks like I don't have the permissions or roles I need to do that."
)
- elif isinstance(e, InChannelCheckFailure):
+ elif isinstance(e, (InChannelCheckFailure, errors.NoPrivateMessage)):
await ctx.send(e)
@staticmethod