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

139
Vistas
How do i call an event inside module.exports?

Am trying to have a reaction role type of command but i keep getting this error. I am trying to have a reaction to be added to my embed command. I tried to have the event in the index.js but ofc it didn't work. Any help would be appreciated.

C:\Users\moham\OneDrive\Desktop\discord_bot\commands\reaction.js:25
    client.on('messageReactionAdd', async(reaction, user) => {

This is my code:

module.exports = {
name: 'reactionrole',
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
    const channel = 'YOUR_CHANNEL';
    const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");
    const blueTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");

    const yellowTeamEmoji = 'YOUR_EMOJI';
    const blueTeamEmoji = 'YOUR_EMOJI';

    let embed = new Discord.MessageEmbed()
        .setColor('#e42643')
        .setTitle('Choose a team to play on!')
        .setDescription('Choosing a team will allow you to interact with your teammates!\n\n'
            + `${yellowTeamEmoji} for yellow team\n`
            + `${blueTeamEmoji} for blue team`);

    let messageEmbed = await message.channel.send(embed);
    messageEmbed.react(yellowTeamEmoji);
    messageEmbed.react(blueTeamEmoji);

    client.on('messageReactionAdd', async (reaction, user) => {
        if (reaction.message.partial) await reaction.message.fetch();
        if (reaction.partial) await reaction.fetch();
        if (user.bot) return;
        if (!reaction.message.guild) return;

        if (reaction.message.channel.id == channel) {
            if (reaction.emoji.name === yellowTeamEmoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
            }
            if (reaction.emoji.name === blueTeamEmoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.add(blueTeamRole);
            }
        } else {
            return;
        }

    });

    client.on('messageReactionRemove', async (reaction, user) => {

        if (reaction.message.partial) await reaction.message.fetch();
        if (reaction.partial) await reaction.fetch();
        if (user.bot) return;
        if (!reaction.message.guild) return;


        if (reaction.message.channel.id == channel) {
            if (reaction.emoji.name === yellowTeamEmoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
            }
            if (reaction.emoji.name === blueTeamEmoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.remove(blueTeamRole);
            }
        } else {
            return;
        }
    });
}

}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Dont add new client events within an event. Instead await reactions from a message.

const filter = (reaction, user) => user.id === message.author.id;
message.awaitReactions({filter, time: 60000})
  .then(reactions => reactions.first())
  .then(reaction => {
    console.log(`${message.author.tag} reacted with ${reaction.emoji.name}`)
  })

Message#awaitReactions

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