Skip to content

Commit c4e62e4

Browse files
committed
Improve error handling with scheduled deletion of infraction messages
1 parent 71cf8ce commit c4e62e4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bot/exts/moderation/infraction/_scheduler.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,18 @@ async def _delete_infraction_message(
114114
115115
This is used to delete infraction messages after a certain period of time.
116116
"""
117-
channel = await get_or_fetch_channel(self.bot, channel_id)
118-
if channel is None:
119-
log.warning(f"Channel {channel_id} not found for infraction message deletion.")
120-
return
121-
122117
try:
118+
channel = await get_or_fetch_channel(self.bot, channel_id)
123119
message = await channel.fetch_message(message_id)
124120
await message.delete()
125121
log.trace(f"Deleted infraction message {message_id} in channel {channel_id}.")
126122
except discord.NotFound:
127-
log.warning(f"Message {message_id} not found in channel {channel_id}.")
123+
log.warning(f"Channel or message {message_id} not found in channel {channel_id}.")
124+
except discord.Forbidden:
125+
log.warning(f"Bot lacks permissions to delete message {message_id} in channel {channel_id}.")
126+
except discord.HTTPException:
127+
log.exception(f"Issue during scheduled deletion of message {message_id} in channel {channel_id}.")
128+
return # Keep the task in Redis on HTTP errors
128129

129130
await self.messages_to_tidy.delete(f"{channel_id}:{message_id}")
130131

0 commit comments

Comments
 (0)