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

Discord.js中message.awaitReactions无法检测到我添加的反应如何处理

问题修复方案
  • 检查并开启Discord Bot对应意图
    Discord.js v13及以上版本强制要求显式声明所需意图,反应收集功能需要开启GUILD_MESSAGE_REACTIONS(服务器消息反应)、DIRECT_MESSAGE_REACTIONS(私信消息反应)意图,同时需要在Discord开发者后台的Bot管理页面开启对应特权意图。
    客户端初始化示例:
    const { Client, GatewayIntentBits } = require('discord.js');
    const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.MessageContent,
        // 如需支持私信场景添加 GatewayIntentBits.DirectMessageReactions
      ]
    });
    
  • 补充消息存在性判断
    现有代码中如果message.reply执行报错,msg会为undefined,收集器自然无法正常工作,可补充校验逻辑:
    const msg = await message.reply("React to this message as quickly as you can.").catch(console.error);
    if(!msg) return; // 新增校验,消息发送失败直接终止逻辑
    
  • 优化filter逻辑
    现有filter中的reaction.emoji.name判断无实际意义,所有表情都存在name属性,可根据你的业务需求调整,比如限定指定表情触发:
    const filter = (reaction, user) => {
      // 示例:仅当用户点击👍表情且为指令触发者时生效
      return reaction.emoji.name === '👍' && user.id === message.author.id;
    };
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 08:27:03