Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I access collected reaction from awaitReactions?

This is my code and I want to access the collected emojis and send them back as a reply. I am also inserting the object I am getting from collected.

Here is the link for the object data: https://pastebin.com/MDm9dsvD

const emojis = [
  'booknquill',
  'balloon1',
  'rail',
  'Alex',
  'cookie1',
  'fish1',
  'Agent',
  'cake1',
  'pickaxe',
  'water',
  'Steve',
  'Apple',
  'carro1t',
  'panda',
  'sign',
  'potion',
  'map1',
  'llama1',
];

let msg = await message.channel.send('`What is your Code ?....`');

for (let i = 0; i < emojis.length; i++) {
  let reactionEmoji = message.guild.emojis.cache.find(
    (emoji) => emoji.name === emojis[i],
  );
  msg.react(reactionEmoji);
}

let reactedEmojis = [];

for (let i = 0; i < emojis.length; i++) {
  reactedEmojis.push(
    message.guild.emojis.cache.find((emoji) => emoji.name === emojis[i]),
  );
}

const filter = (reaction, user) => {
  return !user.bot;
};

msg
  .awaitReactions({ filter, max: 4, time: 60000, errors: ['time'] })
  .then((collected) => {
    console.log(collected.size);
    let userReaction = collected[0];
    console.log(collected[0]);
    message.channel.send(userReaction._emoji.name);
  });

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

collected is a collection, not an array, so you can’t simply access the first item using [0]. You can use methods like .first(), .last(), .at(), etc to access items.

To get the first collected item, you can use let userReaction = collected.first() or let userReaction = collected.at(0).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading