user12657757
user12657757

Reputation:

Detect a reaction Discord.js

Help! I'm developing an RPG bot which it needs to detect reactions. But there are two problems:

  1. It only reacts 1 emoji instead of 4
  2. It tries to detect the reaction only once

Here's my code (There are some things which are in portuguese):

    if (message.channel.name === "rpg") {
    const HP = 0;
    const atk = 0;
    const def = 0;
    const emoji = message.guild.emojis.cache.find(emoji => emoji.name === 'SurvivalManos');
    message.react(emoji);
    const random = Math.ceil(Math.random() * (3 - 0) + 0);
    const rpgembed = new Discord.MessageEmbed()
    .setColor('#ffd15e')
  .setTitle('RPG')
    .setThumbnail('https://cdn.discordapp.com/attachments/732552438283894824/733256439602086019/New_Project_3.png')
    .setTimestamp()
  .setFooter('Feito por R0dr1G02M4R5 com <3; Desenhos de Kunyk');
  if (random == 1) {
    const HP = 50;
    const atk = 10;
    const def = 5;
    rpgembed.setDescription('Um slime verde selvagem apareceu!').setImage('https://media.discordapp.net/attachments/696805791319064618/733967904890159134/SPOILER_New_Piskel.png?width=585&height=585').addFields(

      { name: 'HP', value: HP, inline: true },
      { name: 'Atk', value: atk, inline: true },
      { name: 'Def', value: def, inline: true }
    );
  } else if (random == 2) {
    const HP = 100;
    const atk = 5;
    const def = 10;
    rpgembed.setDescription('Um slime vermelho selvagem apareceu!').setImage('https://media.discordapp.net/attachments/696805791319064618/733968480390610955/SPOILER_New_Piskel_1.png?width=585&height=585').addFields(

      { name: 'HP', value: HP, inline: true },
      { name: 'Atk', value: atk, inline: true },
      { name: 'Def', value: def, inline: true }
    );
  }
  else if (random == 3) {
    const HP = 25;
    const atk = 10;
    const def = 10;
    rpgembed.setDescription('Um feiticeiro fantasma selvagem apareceu!').setImage('https://media.discordapp.net/attachments/696805791319064618/733968482122727494/SPOILER_New_Piskel_2.png?width=585&height=585').addFields(

      { name: 'HP', value: HP, inline: true },
      { name: 'Atk', value: atk, inline: true },
      { name: 'Def', value: def, inline: true }
    );
  }
message.channel.send(rpgembed).then(function(message) {
message.react('⚔').then(() => message.react('🛡')).then(() => message.react('🍖')).then(() => message.react('🏃'))
const filter = (reaction, user) => {
    return ['⚔', '🛡', '🍖', '🏃'].includes(reaction.emoji.name) && user.id === message.author.id;
};


message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
    .then(collected => {
    const reaction = collected.first();
    console.log('he logs');
if (Discord.MessageReaction.emoji === '⚔') {
    message.channel.send("He atacs");
    console.log("He ataks");
    act = false;
  } else if (Discord.MessageReaction.emoji === '🛡') {
    message.channel.send("He defens");
    console.log("He defens");
    act = false;
  } else if (Discord.MessageReaction.emoji === '🍖') {
    message.channel.send("He itz");
    console.log("He itz");
    act = false;
  } else if (Discord.MessageReaction.emoji === '🏃') {
    message.channel.send("He rans");
    console.log("He rans");
    act = false;
  }
})

});

In the console.log('He logs') after message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }) .then(collected => { const reaction = collected.first(); if you check the console, there's only one "He logs"

Plz help. Thanks

Upvotes: 0

Views: 4130

Answers (1)

Diamond
Diamond

Reputation: 122

It only reacts 1 emoji instead of 4

message.react('⚔');
message.react('🛡');
message.react('🍖');
message.react('🏃');

It tries to detect the reaction only once

message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })

Passing max: 1 makes it wait for only 1 reaction. More info here and here

Upvotes: 1

Related Questions