Why is my reaction added event not firing in Discord JS?

Viewed 31

So.. I have been having issues with the Discord JS library when it comes to events, more specifically, the "messageReactionAdd" event. My problem is simple the event does not fire. I have tried other solutions but so far they haven't really worked. It would be very nice if somebody could help.

messageReactionAdded file:

   module.exports = {
    name: 'messageReactionAdd',
    execute(reaction, user) {
        reaction.message.guild.roles.fetch("1020785500983939165") // fetches the role
        .then(role => {
            reaction.message.guild.members.cache.get(user.id).roles.add(role) // adds the role
        })
    }
};

// And here's the main file:

const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits, Guild, Partials } = require('discord.js');
const { token, clientId, guildId } = require('./config.json');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
    ],
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));


for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);
    client.commands.set(command.data.name, command);
}

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
    const filePath = path.join(eventsPath, file);
    const event = require(filePath);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    } else {
        client.on(event.name, (...args) => event.execute(...args));
    }
}

client.login(token);
1 Answers

You may want to add IntentsBitField.Flags.GuildMessageReactions to your intents.

Related