You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py编辑ephemeral消息触发404 NotFound错误怎么解决?

问题原因

Ephemeral(临时)消息是仅触发交互的用户可见、不会在Discord服务器持久存储的特殊消息,你调用msg.edit方法时,底层会调用通用消息编辑接口,通过消息ID+频道ID去服务器查询目标消息,但是服务器根本不会存储ephemeral消息的元数据,所以会返回404未知消息的错误。
同类机器人能正常编辑ephemeral消息,是因为他们用了交互上下文专属的编辑接口,而非通用消息编辑接口。

可行修复方案

方案1:使用交互上下文的编辑方法(最优)

按钮回调触发时传入的ctx是交互上下文对象,自带edit_original_message方法,该方法通过交互令牌而非消息ID定位原始ephemeral消息,完全支持编辑临时消息。
你只需要将on_add_req回调中的await msg.edit(...)替换为await ctx.edit_original_message(...)即可,修改后的代码示例:

@on_click.matching_id("add_req")
async def on_add_req(ctx):
    ActionRow.disable_buttons(row_of_buttons)
    ActionRow.disable_buttons(columns_of_buttons)
    
    embed.title='Add new Requirement'
    embed.description = '**Choose a requirement type**'
    embed.clear_fields()
    embed.set_footer(text='')
 
    # 替换原来的msg.edit为ctx.edit_original_message,参数完全一致,不需要额外传ephemeral
    await ctx.edit_original_message(
        embed = embed, 
        components = [
            row_of_buttons, 
            columns_of_buttons,
            SelectMenu(
                custom_id="add_req_menue",
                placeholder="Select a requirement type",
                max_values=1,
                options=[
                    SelectOption("Account Older",'1', "Must be a certain amount of days old"),
                    SelectOption("Member Older", "2" , "Must be a member for a certain amount of days"),
                    SelectOption("Role", "3" , "Member must have the specified role"),
                    SelectOption("Not Role" ,"4","Member must **not** have the specific role"),
                    SelectOption("Messages" , "5" , "Must have sent the specified amount of messages"),
                    SelectOption("Badge" , "6" , "Member must have the specified badge"),
                    SelectOption("Tag" , "7" , "Member must have the specified operator"),
                    SelectOption("Voice Duration" , "8" , "Have been in VC for a certain amount of minutes"),
                    SelectOption("Status" , "9", "Member must have the specific status(es)"),
                    SelectOption("Bio" , "10" , "Member must have this in their custom status"),
                    SelectOption("Name" , "11" , "Member must have this in their name"),
                    SelectOption("Activity" , "12" , "Member must meet a specified activity threshold")
                ]
            )
        ]
    )

方案2:升级依赖库

你当前使用的dislash是第三方扩展库,部分旧版本对交互编辑的适配存在问题,你可以选择:

  • 升级dislash到最新正式版
  • 迁移到官方discord.py v2.x版本,原生支持斜杠命令、组件和ephemeral消息编辑,兼容性更好

方案3:取消ephemeral属性(备选)

如果不需要隐藏创建流程,可以将发送消息时的ephemeral=True改为ephemeral=False,此时消息会公开存储在频道中,通用msg.edit方法就可以正常调用,但该方案会暴露抽奖配置过程,不推荐使用。

内容的提问来源于stack exchange,提问作者Hiresh Verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 15:27:04