Javascript Discord.js V12 messageReactionAdd仅在bot响应时激发

Javascript Discord.js V12 messageReactionAdd仅在bot响应时激发,javascript,discord.js,Javascript,Discord.js,将我的bot从V11升级到V12.1.1我有一条消息reactionadd as client.on("messageReactionAdd", (reaction, user) => { console.log("Reaction added"); if (user.id == client.user.id){return console.log("Reaction is from Lillette");} const chanid = reaction.message.ch

将我的bot从V11升级到V12.1.1我有一条消息reactionadd as

client.on("messageReactionAdd", (reaction, user) => {
  console.log("Reaction added");
  if (user.id == client.user.id){return console.log("Reaction is from Lillette");}
  const chanid = reaction.message.channel.id;
  console.log(chanid);
  let chanchk = (reactchannels.indexOf(chanid) > -1);
  console.log(chanchk);
  if(chanchk === false){return console.log("Reaction not in a valid channel");}


  for (var i = 0; i < reactchannels.length; i++){
    if (reactchannels[i] == chanid && i == 0){arrayn = reactnames.one, arrayr = reactroles.one, console.log(`Success at i=${i}`);}
    else if (reactchannels[i] == chanid && i == 1){arrayn = reactnames.two, arrayr = reactroles.two, console.log(`Success at i=${i}`);}
    else {arrayn = [], arrayr = [];}
    if(arrayn.length !== arrayr.length){/*return*/ console.log("Arrays not equal length");}

    const emoji = reaction.emoji.name; //"cat";
    const guildmem = reaction.message.guild.members.cache.get(user.id);
    for (var e = 0; e < arrayn.length; e++) {
      if (emoji == arrayn[e]) {
        console.log(`Found emoji named ${arrayn[e]}, corresponding role = ${arrayr[e]}`);
        var findrole = reaction.message.guild.roles.cache.find(g => g.name === arrayr[e]);
        if (findrole == null) {return console.log("User has reacted with a valid emoji, but the role does not exist in the guild");}//End if no roles found
        guildmem.roles.add(`${findrole.id}`);//assign role
        return; //no need to continue loop if role found
      }//End of if
      //else {console.log(`No roles found for ${arrayn[e]}`);}
    }//End of for e
  }//end of for i
  if (arrayn.length == 0 || arrayr.length == 0){/*return*/ console.log("END -- arrayn or arrayr lengths are equal to 0");}
});
client.on(“messageReactionAdd”,(reaction,user)=>{
控制台日志(“添加的反应”);
if(user.id==client.user.id){return console.log(“反应来自Lillette”);}
const chanid=reaction.message.channel.id;
console.log(chanid);
设chanchk=(reactchannels.indexOf(chanid)>-1);
控制台日志(chanchk);
if(chanchk==false){return console.log(“反应不在有效通道中”);}
对于(var i=0;ig.name===arrayr[e]);
if(findrole==null){return console.log(“用户已使用有效的表情符号作出反应,但该角色在公会中不存在”);}//如果未找到角色,则结束
guildmem.roles.add(`${findrole.id}`);//分配角色
return;//如果找到角色,则无需继续循环
}//if结束
//else{console.log(`No roles found for${arrayn[e]}`);}
}//结束对e的访问
}//我的工作结束了
如果(arrayn.length==0 | | arrayr.length==0){/*return*/console.log(“END--arrayn或arrayr长度等于0”);}
});
是的,它不整洁,但它不会通过第2行
console.log(“添加的反应”)除非bot对消息做出反应,在这种情况下,由于第3行的原因,bot返回。Channel/emoji/emojinames/arrayn/arrayr是在代码上面定义的,但在这一点上似乎并不相关

有人能告诉我为什么用户(包括我自己和alt帐户)在与机器人相同的频道/消息中使用相同的表情符号时不注册反应事件(消防线2)


编辑:在这两种情况下,响应的消息都是在打开bot后发送的。类似地,下面的代码中包含了一个原始反应事件,用于捕获和处理未缓存的消息(但由于更简单的MessageReactionaAdd不起作用,尚未调试)。

似乎与下面的原始事件有冲突。上面的代码应该独立工作。

似乎与下面的原始事件有冲突。上面的代码应该可以独立运行。

请确保消息是在bot启动后发送的感谢您指出这一点,我已经更新了OP。这两个实例消息都是在bot启动后发送的,我有一个原始的反应事件来抓取未缓存的消息(但还没有看到是否有效)。请确保消息在bot启动后发送感谢您指出这一点,已更新OP。两个实例消息都是在bot启动后发送的,我有一个原始的反应事件来抓取未缓存的消息(但尚未看到是否有效)。如果您的问题得到回答,请将其删除或用绿色勾号将其标记为接受答案。如果您的问题得到回答,请将其删除或用绿色勾号将其标记为接受答案