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

Discord.py 2.0中无法为交互消息添加反应的问题求助

Discord.py 2.0 交互消息添加反应失败的解决方案

错误原因

你遇到的AttributeError源于两个核心问题:

  1. 通过@bot.tree.command()定义的Slash命令,其interaction.message属性本身就是None——这类命令由Discord交互系统触发,并非基于用户发送的普通消息,不存在关联的原始消息对象。
  2. interaction.response.send_message()方法的返回值是None,你赋值的message变量并没有指向实际发送出去的响应消息。

修复后的代码

@bot.tree.command()
@app_commands.describe(question="Give a title")
async def poll(interaction: discord.Interaction, question: str):
    emb = discord.Embed(title=f":bar_chart: {question}", type="rich")

    # 发送交互响应
    await interaction.response.send_message(embed=emb)
    # 获取刚发送的响应消息对象
    response_message = await interaction.original_response()
    # 添加反应
    await response_message.add_reaction("✅")

关键要点

  • 使用interaction.original_response()获取交互的初始响应消息,这是Discord.py 2.0中获取此类消息对象的标准方式。
  • Slash命令场景下,interaction.message属性永远为None,不要尝试使用它。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 17:25:26