I’m running into a problem where my Discord bot cannot modify a message after I send it. When I try to retrieve the message using its ID and then edit it, I keep getting this error:
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
Here’s the code that reproduces this issue:
import asyncio
import discord
from discord.ext import commands
from discord.commands import slash_command
class MessageEditor(commands.Cog):
def __init__(self, client):
self.client = client
@slash_command(name='edit_test', description='Test message editing')
async def edit_test(self, context):
message_embed = discord.Embed(
description="Original message content"
)
sent_message = await context.respond(embed=message_embed, ephemeral=True)
message_id = sent_message.id
await asyncio.sleep(2)
target_channel = self.client.get_channel(context.channel_id)
retrieved_message = await target_channel.fetch_message(message_id)
updated_embed = discord.Embed(
description="Updated message content"
)
await retrieved_message.edit(embed=updated_embed)
def setup(client):
client.add_cog(MessageEditor(client))
I need to fetch the message from the channel first before editing it. This approach should work but it’s throwing the unknown message error. Any ideas what might be causing this?