Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Collect reaction from dm message triggered by 'guildMemberAdd'

My bot sends a message when a new member is added to the guild. The message goes to a specific user.

    client.on('guildMemberAdd', member => {
    const adminDm = client.users.cache.get(Config.get('ADMIN'));
    client.commands.get('novoMembro').execute(member, adminDm);
}); 

Now I need to collect the reaction in order to assign some role to the new member.

const Discord = require('discord.js');

module.exports = {
    name: 'novoMembro',
    description: "Adding a new member to the guild",
    execute(member, adminDm){
        const novoMembroEmbed = new Discord.MessageEmbed()
        .setColor([153,0,76])
        .setTitle('NOVO MEMBRO ADICIONADO')
        .setDescription(`<@!${member.id}> foi adicionado`)
        .addFields( 
            {name: 'Selecione uma opção:', value: 'Reaja com 📨 para enviar mensagem de boas vindas \n Reaja com ❌ para cancelar'},
        );

        adminDm.send({ embeds: [novoMembroEmbed] }).then((msg => {
            msg.react('❌');
            msg.react('📨');
        }));
        
       
    }
}

Until this point, the code works fine. But I can't find a way to collect the reactions, every code I've tried doesn't work. I think I didn't understand right the concept of collecting reactions. these are some code I've tried.

const filter = (reaction) => ['❌', '📨'].includes(reaction.emoji.name);
const reactOptions = {maxEmojis: 1};

.then(() => msg.awaitReactions(filter, reactOptions)).then(collected => {
                if (collected.first().emoji.name === '📨') {
                    console.log('msg de boas vindas');
                }else{
                    console.log('cancelando');
                }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are a couple of errors with your code. In discord.js v13 the awaitReactions and createReactionCollector accepts a single parameter and the filter is part of the options object now. (See Changes in v13.) So, you need to update that; pass down a single object with a filter and a max or maxEmojis key.

You'll also need to update your filter as it currently collects the bot's reactions too. By checking if the user who reacted is the same as the admin, you can make sure you only collect the reactions you need.

You could also make execute async and use the await keyword to wait for the promises to be resolved.

And one last thing; make sure you enabled the required intents: DIRECT_MESSAGES and DIRECT_MESSAGE_REACTIONS.

Check out the code below:

module.exports = {
  name: 'novoMembro',
  description: 'Adding a new member to the guild',
  async execute(member, admin) {
    const novoMembroEmbed = new Discord.MessageEmbed()
      .setColor([153, 0, 76])
      .setTitle('NOVO MEMBRO ADICIONADO')
      .setDescription(`<@!${member.id}> foi adicionado`)
      .addFields({
        name: 'Selecione uma opção:',
        value:
          'Reaja com 📨 para enviar mensagem de boas vindas \n Reaja com ❌ para cancelar',
      });

    try {
      const sentDM = await admin.send({ embeds: [novoMembroEmbed] });
      // make sure you don't collect the bot's reactions
      const filter = (reaction, user) =>
        ['❌', '📨'].includes(reaction.emoji.name) && user.id === admin.id;

      sentDM.react('❌');
      sentDM.react('📨');

      // add a single options object only
      const collected = await sentDM.awaitReactions({ filter, maxEmojis: 1 });

      if (collected.first().emoji.name === '📨') {
        admin.send('msg de boas vindas');
      } else {
        admin.send('cancelando');
      }
    } catch (err) {
      console.log(err);
    }
  },
};

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda