store message.id instead of message in reroll history

This commit is contained in:
2025-08-21 10:36:14 -07:00
parent 3d9c5d8e71
commit 8437cc6940

14
bot.py
View File

@@ -44,7 +44,7 @@ async def discord_send(channel, text, name, avatar=DEFAULT_AVATAR):
) )
else: else:
message = await channel.send(content=chunk) message = await channel.send(content=chunk)
messages.append(message) messages.append(message.id)
return messages return messages
async def webhook(channel): async def webhook(channel):
@@ -102,14 +102,22 @@ async def on_reaction_add(reaction, user):
message = reaction.message message = reaction.message
channel = message.channel channel = message.channel
conversation = await Conversation.get(channel.id) conversation = await Conversation.get(channel.id)
if message not in conversation.last_messages: if message.id not in conversation.last_messages:
await reaction.clear() await reaction.clear()
return return
print(f"_ {user}: {reaction}") print(f"_ {user}: {reaction}")
try: try:
async with channel.typing(): async with channel.typing():
for message in conversation.last_messages: try:
messages = [
await channel.fetch_message(message_id)
for message_id in conversation.last_messages
]
except (discord.NotFound, discord.Forbidden):
# don't do anything if any message in the list is not found
await reaction.clear()
for message in messages:
await message.delete() await message.delete()
response = await conversation.regenerate() response = await conversation.regenerate()
conversation.last_messages = await discord_send( conversation.last_messages = await discord_send(