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 <alekratz@gmail.com>
This commit is contained in:
2022-10-23 18:07:32 -07:00
parent fa3f40c910
commit c1ff96b566

View File

@@ -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: