1
votes

Upgrading my bot from V11 to V12.1.1 I have a 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"); 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.

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?

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).

1
Make sure that the message is sent after the bot startedPLASMA chicken
Thanks for pointing this out, have updated OP. Both instances message in question has been after the bot has been booted and I have a raw reaction event to grab uncached messages (but not up to seeing if that works yet).Todgins

1 Answers

0
votes

Seemed to be having a conflict with the raw events below. Code above should work standalone.