简体   繁体   English

仅从消息中删除一种反应 (Discord.js)

[英]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.根据文档, MessageReaction.remove()删除整个反应,而不仅仅是 1 个用户。 If you call the remove() function on the ReactionUserManager, you can remove 1 user from the reaction.如果您在 ReactionUserManager 上调用remove()函数,您可以从反应中删除 1 个用户。

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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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