From c4e62e4a958c08fdf61e21375b7a98c1c05ce2dd Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Mon, 23 Jun 2025 06:51:03 +0100 Subject: Improve error handling with scheduled deletion of infraction messages --- bot/exts/moderation/infraction/_scheduler.py | 13 +++++++------ 1 file 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}") -- cgit v1.2.3