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

Discord.py:如何为机器人自身发送的消息添加表情反应?

问题分析与解决办法

你的核心问题是没有保存机器人发送的消息对象,而且命令参数里的**message完全用错了,导致你调用add_reaction时根本没指向机器人自己发的那条消息。

具体错误点:

  • **message这个参数是多余且错误的,discord.py的命令参数里,这样写只会捕获关键字参数,根本不是你要的消息对象。
  • 你调用await bot.get_channel(moderator_channel).send(embed=embed)时,没有把返回的消息存下来,这条send方法会返回机器人发送的Message对象,只有对这个对象调用add_reaction才会生效。
  • 之前试的ctx.message是用户触发命令时发的消息,所以只会给用户的消息加反应;bot.message、client.message这类属性根本不存在,自然报错。

修正后的代码:

bot = commands.Bot(command_prefix = "!", intents=intents)

@bot.command(pass_context=True)
async def rnick(ctx, *, nick):
    embed=discord.Embed(color=embed_color)
    embed.add_field(name="****", value="*******************", inline=False)
    embed.add_field(name="*********", value="******", inline=True)
    embed.add_field(name="*******",value="*****")
    embed.set_footer(text=str(ctx.author.id) + "  •  " + ct)
    # 保存机器人发送的消息对象
    sent_msg = await bot.get_channel(moderator_channel).send(embed=embed)
    # 对保存的消息对象添加反应
    await sent_msg.add_reaction("✅")
    await sent_msg.add_reaction("❌")

额外注意事项:

  1. 确保你的机器人在moderator_channel这个频道里有添加反应的权限。
  2. 检查intents配置,至少开启messages相关的intents(如果是discord.py v2.x,还需要开启message_content),否则机器人可能无法正确处理消息相关操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 15:22:10