Skip to content

Commit bf9e84f

Browse files
committed
Gracefully handle attempting tidy-up in archived thread
1 parent 45ced59 commit bf9e84f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

bot/exts/moderation/infraction/_scheduler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
AUTOMATED_TIDY_UP_HOURS = 8
3030

31+
# Error when trying to delete a message in an archived thread.
32+
ARCHIVED_THREAD_ERROR = 50083
3133

3234
class InfractionScheduler:
3335
"""Handles the application, pardoning, and expiration of infractions."""
@@ -122,9 +124,14 @@ async def _delete_infraction_message(
122124
log.warning(f"Channel or message {message_id} not found in channel {channel_id}.")
123125
except discord.Forbidden:
124126
log.info(f"Bot lacks permissions to delete message {message_id} in channel {channel_id}.")
125-
except discord.HTTPException:
126-
log.exception(f"Issue during scheduled deletion of message {message_id} in channel {channel_id}.")
127-
return # Keep the task in Redis on HTTP errors
127+
except discord.HTTPException as e:
128+
if e.code == ARCHIVED_THREAD_ERROR:
129+
log.info(
130+
f"Cannot delete message {message_id} in channel {channel_id} because the thread is archived."
131+
)
132+
else:
133+
log.exception(f"Issue during scheduled deletion of message {message_id} in channel {channel_id}.")
134+
return # Keep the task in Redis on HTTP errors
128135

129136
await self.messages_to_tidy.delete(f"{channel_id}:{message_id}")
130137

0 commit comments

Comments
 (0)