aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2025-06-23 06:51:03 +0100
committerGravatar Joe Banks <[email protected]>2025-06-23 06:52:11 +0100
commitc4e62e4a958c08fdf61e21375b7a98c1c05ce2dd (patch)
treef2f406520105c7e1f3b1b9f15a5788538a5b1acf
parentDelete automated infraction messages after a period of time (diff)
Improve error handling with scheduled deletion of infraction messages
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 7610ec04c..11d5404a9 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -114,17 +114,18 @@ class InfractionScheduler:
This is used to delete infraction messages after a certain period of time.
"""
- channel = await get_or_fetch_channel(self.bot, channel_id)
- if channel is None:
- log.warning(f"Channel {channel_id} not found for infraction message deletion.")
- return
-
try:
+ channel = await get_or_fetch_channel(self.bot, channel_id)
message = await channel.fetch_message(message_id)
await message.delete()
log.trace(f"Deleted infraction message {message_id} in channel {channel_id}.")
except discord.NotFound:
- log.warning(f"Message {message_id} not found in channel {channel_id}.")
+ log.warning(f"Channel or message {message_id} not found in channel {channel_id}.")
+ except discord.Forbidden:
+ log.warning(f"Bot lacks permissions to delete message {message_id} in channel {channel_id}.")
+ except discord.HTTPException:
+ log.exception(f"Issue during scheduled deletion of message {message_id} in channel {channel_id}.")
+ return # Keep the task in Redis on HTTP errors
await self.messages_to_tidy.delete(f"{channel_id}:{message_id}")