Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda