From c1ff96b566d6ec2e627cc3f646f9ea6119e082a8 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 23 Oct 2022 18:07:32 -0700 Subject: [PATCH] Fix missing message id from channel Sometimes, last_message_id points to a message in a channel that is "not found". This is OK because we're just figuring out when the last message was sent, and we use the current time instead. Signed-off-by: Alek Ratzloff --- discord_markov/client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/discord_markov/client.py b/discord_markov/client.py index 1e66607..2001259 100644 --- a/discord_markov/client.py +++ b/discord_markov/client.py @@ -157,8 +157,13 @@ class Client(discord.Client): # NOTE: there is a channel.last_message property, but it's unreliable. # fetch_message(last_message_id) will always yield a # message if there's a valid ID - message = await channel.fetch_message(channel.last_message_id) - self.set_last_tracked_message(channel.id, message.created_at) + try: + message = await channel.fetch_message(channel.last_message_id) + last_message = message.created_at + except discord.errors.NotFound: + # sometimes the last message is just not found. What to heck?? + last_message = util.utcnow() + self.set_last_tracked_message(channel.id, last_message) async def on_message(self, message: discord.Message): if message.author.bot: