Unable to modify Discord bot message after sending

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?

You’re mixing interaction responses with regular message handling. When you use context.respond(), it creates an interaction response that doesn’t work like a normal Discord message. The sent_message.id you get isn’t a valid message ID for channel fetching - especially with ephemeral responses. I’ve hit this exact issue switching from regular commands to slash commands. Don’t try fetching the message again - work directly with the interaction response object. Either use sent_message.edit_original_response() like mentioned, or if you need a regular message object, use await context.send() instead of context.respond(). That creates a proper message you can fetch and edit through normal channel methods.

The problem is that context.respond() returns an interaction response object, not a regular message object. You can’t fetch ephemeral messages through normal channel methods - they exist in a different context entirely. Skip the fetching altogether. Store the response object and use await sent_message.edit_original_response(embed=updated_embed) to modify it. This works for both ephemeral and regular responses. Your current approach won’t work because ephemeral messages aren’t accessible through normal channel message retrieval.

ephemeral messages can only be seen by the user who triggered them, that’s why you get that error. just try removing ephemeral=True and it should work for you!