【问题标题】:Removing just one reaction from message (Discord.js)从消息中删除一个反应(Discord.js)
【发布时间】:2021-01-04 03:59:10
【问题描述】:

我正在创建一个嵌入,您可以在其中通过反应浏览页面。通过遵循教程,我想出了这个问题,但问题是:当用户对其做出反应时,它会删除所有相同类型的反应(基本上,如果我对❤️做出反应,机器人会删除我和他们的反应,让 ⚙️ 成为唯一的反应反应可用)

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

希望你能理解我的问题,我只是想让机器人消除我的反应,而不是全部。

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    根据文档,MessageReaction.remove() 删除了整个反应,而不仅仅是 1 个用户。如果你在 ReactionUserManager 上调用 remove() 函数,你可以从反应中删除 1 个用户。

    看看下面的示例代码并尝试一下。

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

    【讨论】:

      猜你喜欢
      • 2021-05-18
      • 2021-06-21
      • 2020-02-21
      • 2021-11-13
      • 2018-08-26
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      相关资源
      最近更新 更多