diff options
| author | 2019-12-09 23:34:30 -0800 | |
|---|---|---|
| committer | 2019-12-09 23:34:30 -0800 | |
| commit | d0e14dca855179bd71c46747ecf63d4038045881 (patch) | |
| tree | d5656d6df98250dd54876c52a67197ec3a2fb80a | |
| parent | Moderation: show HTTP status code in the log for deactivation failures (diff) | |
Moderation: catch HTTPException when applying an infraction
Only a warning is logged if it's a Forbidden error. Otherwise, the whole
exception is logged.
| -rw-r--r-- | bot/cogs/moderation/scheduler.py | 10 | 
1 files changed, 7 insertions, 3 deletions
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py index 703b09802..8e5b4691f 100644 --- a/bot/cogs/moderation/scheduler.py +++ b/bot/cogs/moderation/scheduler.py @@ -146,14 +146,18 @@ class InfractionScheduler(Scheduler):                  if expiry:                      # Schedule the expiration of the infraction.                      self.schedule_task(ctx.bot.loop, infraction["id"], infraction) -            except discord.Forbidden: +            except discord.HTTPException as e:                  # Accordingly display that applying the infraction failed.                  confirm_msg = f":x: failed to apply"                  expiry_msg = ""                  log_content = ctx.author.mention                  log_title = "failed to apply" -                log.warning(f"Failed to apply {infr_type} infraction #{id_} to {user}.") +                log_msg = f"Failed to apply {infr_type} infraction #{id_} to {user}" +                if isinstance(e, discord.Forbidden): +                    log.warning(f"{log_msg}: bot lacks permissions.") +                else: +                    log.exception(log_msg)          # Send a confirmation message to the invoking context.          log.trace(f"Sending infraction #{id_} confirmation message.") @@ -324,7 +328,7 @@ class InfractionScheduler(Scheduler):                      f"Attempted to deactivate an unsupported infraction #{id_} ({type_})!"                  )          except discord.Forbidden: -            log.warning(f"Failed to deactivate infraction #{id_} ({type_}): bot lacks permissions") +            log.warning(f"Failed to deactivate infraction #{id_} ({type_}): bot lacks permissions.")              log_text["Failure"] = f"The bot lacks permissions to do this (role hierarchy?)"              log_content = mod_role.mention          except discord.HTTPException as e:  |