Home > front end >  Discord.js messageReactionAdd ignore users
Discord.js messageReactionAdd ignore users

Time:08-01

I'm trying to add listening to my bot by adding roles to reactions. And it works, but only when the bot itself adds reactions. When any other user does this, the bot ignores it. role-claim file where creat message for first message and creatind role - emoji for it:

const firstMessage = require('./first-message')


module.exports = (client) => {
    const channelId = '813819563703271484'

    const getEmoji = (emojiName) => client.emojis.cache.find((emoji) => emoji.name === emojiName)

    const emojis = {
        mercedes: 'Mercedes',
        ferrari: 'FERRARI',
        renault: 'RENAULT'
    }

    const reactions = []

    let  emojiText = 'Pick any team \n\n'
    for (const key in emojis) {
    const emoji = getEmoji(key)
    
    reactions.push(emoji)
    const role = emojis[key]
    emojiText  = `${emoji} = ${role} \n` 

    }

    firstMessage(client, channelId, emojiText, reactions);

    client.on('messageReactionAdd', (reaction, user) =>{
        console.log("add");
    })
    client.on('messageReactionRemove', (reaction, user) =>{
        console.log("Remove");
    })
}

first-message create or edit first message and add reactions

    message.react(reactions[0])
    reactions.shift()
    if (reactions.length > 0) {
        setTimeout (() => addReactions(message, reactions), 750)
    }
}

module.exports = async (client, id, text, reactions = []) => {
    const channel = await client.channels.fetch(id)

    channel.messages.fetch().then((messages) =>{
        if (messages.size === 0){
            // 
            channel.send(text).then((message) => {
                addReactions(message, reactions)
            })
        } else {
            //
            for (const message of messages){
                message[1].edit(text)
                addReactions(message[1], reactions)   
            }
         
        }
    })
    
}

Index.js main bot file

const  rest  = require('@discordjs/rest');
const  Routes  = require('discord-api-types/v9');
const { MessageEmbed } = require('discord.js');
const { Client, Intents } = require('discord.js');
const rolechannel = '813819563703271484';
const roleClaim = require('./role-claim')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.login("||||||||||||||"); 
const config = require("./config.json");


client.on("ready", () => {
    client.user.setActivity("altV: Multiplayer on FreeZone", { type: "PLAYING" })
    console.log("1000-7");
    roleClaim(client);
})

CodePudding user response:

I believe you need the GUILD_MESSAGE_REACTIONS intent for this to work.

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS] });
  • Related