简体   繁体   English

Discord.js V12 messageReactionAdd 仅在机器人做出反应时触发

[英]Discord.js V12 messageReactionAdd only fires when bot reacts

Upgrading my bot from V11 to V12.1.1 I have a messageReactionAdd as将我的机器人从 V11 升级到 V12.1.1 我有一个 messageReactionAdd 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");}
});

Yes it's untidy but It will not pass line 2 console.log("Reaction added");是的,它很不整洁,但它不会通过第 2 行console.log("Reaction added"); except when the bot reacts to a message, in which case it returns due to line 3. Channel/emoji/emojinames/arrayn/arrayr are defined above the code but don't seem relevant at this point.除非机器人对消息做出反应,在这种情况下,它会由于第 3 行而返回。 Channel/emoji/emojinames/arrayn/arrayr 在代码上方定义,但此时似乎不相关。

Can anyone point me towards why a user (both myself and an alt account) does not register a reaction event (fire line 2) when using the same emoji in the same channel/message as the bot?谁能指出为什么用户(我自己和 alt 帐户)在与机器人在同一频道/消息中使用相同的表情符号时没有注册反应事件(火线 2)?

EDIT: In both cases the message reacted to IS sent AFTER the bot is turned on.编辑:在这两种情况下,响应的消息都是在机器人打开后发送的。 And similarly a raw reaction event is included in the code below to grab and handle uncached messages (but not yet being debugged as the simpler, messageReactionAdd is not working).同样,下面的代码中包含一个原始反应事件,以获取和处理未缓存的消息(但尚未调试为更简单,messageReactionAdd 不起作用)。

Seemed to be having a conflict with the raw events below.似乎与下面的原始事件发生冲突。 Code above should work standalone.上面的代码应该独立工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM