Improve message deletion logic to handle timeout messages and skip invalid webhook token errors

This commit is contained in:
2025-01-26 03:52:36 +01:00
parent a08b7e7cd7
commit fb1db7f222

View File

@ -109,13 +109,15 @@ class RemindBotClient(discord.Client):
logger.debug("Removing view: %s", msg.id) logger.debug("Removing view: %s", msg.id)
try: try:
# If the message is "/remind list timed out.", skip it # If the message is "/remind list timed out.", skip it
if msg.content == "/remind list timed out.": if "/remind list timed out." in msg.content:
logger.debug("Message %s is a timeout message. Skipping.", msg.id) logger.debug("Message %s is a timeout message. Skipping.", msg.id)
continue continue
await msg.delete() await msg.delete()
except discord.HTTPException as e: except discord.HTTPException as e:
logger.error("Failed to remove view: %s", e) # noqa: TRY400 if e.status != 401:
# Skip if the webhook token is invalid
logger.error("Failed to remove view: %s", e) # noqa: TRY400
except asyncio.exceptions.CancelledError: except asyncio.exceptions.CancelledError:
logger.error("Failed to remove view: Task was cancelled.") # noqa: TRY400 logger.error("Failed to remove view: Task was cancelled.") # noqa: TRY400