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

Nextcord斜杠命令响应添加反应报错,求正确实现方法

解决Nextcord斜杠命令响应消息添加反应的问题

斜杠命令里ctx.send()默认返回的是PartialInteractionMessage对象,该对象仅包含交互消息的部分数据,没有add_reaction方法,这就是报错的核心原因。

你可以通过以下两种方式实现需求:

  • 方法一:添加wait=True获取完整消息对象
    在ctx.send()中传入wait=True参数,会等待消息发送完成并返回完整的Message实例,之后就能正常调用add_reaction方法:

    @bot.slash_command(name='test', description="Test.")
    async def test(ctx):
        msg = await ctx.send("Hello.", wait=True)
        await msg.add_reaction('🤖')
    
  • 方法二:通过fetch_message拉取完整消息
    先发送消息得到部分对象,再利用频道的fetch_message方法,通过消息ID获取完整的Message对象:

    @bot.slash_command(name='test', description="Test.")
    async def test(ctx):
        partial_msg = await ctx.send("Hello.")
        msg = await ctx.channel.fetch_message(partial_msg.id)
        await msg.add_reaction('🤖')
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 22:48:50