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

使用discord.py编辑消息报错:'coroutine' object has no attribute 'edit'

问题解决:discord.py编辑消息报错AttributeError

错误原因

  1. 未正确等待异步方法:client.fetch_message()是异步函数,直接赋值给msg会得到一个协程对象,而非实际的Message实例,自然没有edit方法。
  2. 参数传递错误:msg.edit()中,content参数用于传递文本内容,文件需要通过file参数传入,不能把discord.File传给content。

修正后的代码

chat = client.get_channel(1007301750895677491)
# 必须用await获取Message对象
msg = await client.fetch_message(1007556250134917170)
# 用file参数传递文件,可同时设置content文本(可选)
await msg.edit(content="本周结果:", file=discord.File('week_result.png'))

额外说明

  • 如果不需要文本内容,仅替换为图片,可省略content参数:
    await msg.edit(file=discord.File('week_result.png'))
    
  • 确保你的bot拥有编辑消息的权限,并且目标消息确实存在于指定频道中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 13:36:29