I’m working on a Discord bot using discord.py that needs to monitor message edits on posts with embedded content. The bot works fine when it’s online and the original message gets posted. But I’m having trouble with messages that were created while my bot was down or disconnected.
Is there a way to make the on_message_edit event work for messages that existed before the bot came online? I tried using Channel.history() to grab old messages but the edit detection still doesn’t work for them.
I think the issue is that these older messages aren’t stored in the bot’s internal cache. I know about TextChannel.fetch_message(id) but that doesn’t seem to add messages to the cache either.
Any ideas on how to solve this? I need my bot to track edits on messages even if they were posted during bot restarts.
You’ve hit a Discord limitation. The on_message_edit event only fires for messages Discord actively sends edit notifications for - it won’t catch edits that happened while your bot was offline. You need a different approach. Skip the edit event and use a periodic check system instead. Store message IDs and their content/embed data in a database, then periodically fetch those messages with fetch_message() and compare against what you’ve stored. This catches edits that happened during downtime. I had the same problem with a moderation bot and ended up running a background task that checks important messages every few minutes. It’s not real-time but it’s reliable. Just watch your API calls and respect rate limits.
yeah, discord.py’s cache system can be a pain. i made a webhook listener that grabs edits instantly, even when the bot’s not online. it’s a bit of a hassle to set up but way better than spamming the API for updates. also, consider using the audit log for tracking changes, but it’s limited to some message types.
Discord’s gateway events only fire for cached messages, and anything from before the bot started isn’t cached. Hit this same issue with a content monitoring bot last year. Here’s what worked: keep using on_message_edit for real-time stuff, but add a startup routine that grabs recent messages from your target channels and dumps their current state into your database. Then run periodic checks comparing your stored data against fresh API calls to catch edits during downtime. Don’t try monitoring everything though - you’ll hit rate limits fast. Be selective about what you track: messages with embeds, specific users, or certain channels. This setup’s been bulletproof for handling restarts and network hiccups.