【问题标题】:Getting the amount of users who reacted to a message with a certain emoji获取使用特定表情符号对消息做出反应的用户数量
【发布时间】:2018-08-18 18:05:03
【问题描述】:

如何获取对特定消息使用表情符号做出反应的用户数量

message.channel.fetchMessage(message.id).then(function(r){
    return console.log(r.reactions.filter(a => a.emoji.name == '????')).users.size
})

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    这是一个非常有趣的问题,我不确定为什么,但 users 属性似乎并不总是准确的。此外,users 是一个 Collection,它没有 .size 属性。

    相反,我建议使用<MessageReaction>.count 属性。像这样:

    message.channel.fetchMessage('<message id>')
    .then(msg => {
        let downVoteCollection = msg.reactions.filter(rx => rx.emoji.name == '?');
    
        console.log(downVoteCollection.first().count);
    })
    .catch(console.error);
    

    您可以使用Collection.first() 方法,因为您只会返回不赞成的表情符号,因此该集合中只会返回一种MessageReaction

    【讨论】:

      【解决方案2】:

      &lt;MessageReaction&gt; 有一个 count 属性,它返回

      给出相同反应的人数

      这正是您要查找的内容,因此您可以映射集合以获取 count 属性,如下所示:

      message.channel.fetchMessage(message.id).then(r => {
          return console.log(r.reactions.filter(a => a.emoji.name == '?').map(reaction => reaction.count)[0]);
      });
      

      【讨论】:

        猜你喜欢
        • 2020-07-22
        • 2021-10-05
        • 1970-01-01
        • 2019-12-27
        • 2020-09-19
        • 2021-02-06
        • 2021-12-17
        • 2019-02-03
        • 1970-01-01
        相关资源
        最近更新 更多