简体   繁体   中英

Removing just one reaction from message (Discord.js)

I am creating an embed where you can navigate through pages by reacting. By following a tutorial I came up with this but here's the problem: it removes all reactions of the same kind when the user react to it (basically If I react with ❤️, the bot removes either my reaction and theirs, letting ⚙️ be the only reaction available)

let embed= new Discord.MessageEmbed()
            .setTitle(Title)
            .setURL(url)
            .setThumbnail(image)
const filter1 = (reaction, user) => reaction.emoji.name === '⚙️' && user.id === message.author.id
const filter2 = (reaction, user) => reaction.emoji.name === '❤️' && user.id === message.author.id
let msg = await message.channel.send(embed)
            await msg.react('⚙️')
            await msg.react('❤️')
const collector1= await msg.createReactionCollector(filter1, {time: 60000})
const collector2= await msg.createReactionCollector(filter2, {time: 60000})
collector1.on('collect', async r => {
                embed.setDescription('Page 1')
                r.remove(message.author.id) // <<== This removes also the bot reaction
                msg.edit(embed)
            })
collector2.on('collect', async r => {
                embed.setDescription('Page 2') 
                r.remove(message.author.id) // <<== This removes also the bot reaction
                msg.edit(embed)
            })

Hopefully, you understood my problem, I just wanted to have the bot removing my reaction, not all.

According to the docs, MessageReaction.remove() removes the entire reaction, not just 1 user. If you call the remove() function on the ReactionUserManager, you can remove 1 user from the reaction.

Take a look at the example code below and give it a try.

collector1.on('collect', async (reaction, user) => {
    embed.setDescription('Page 1');
    reaction.users.remove(user);
    msg.edit(embed);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM