【问题标题】:How do you get every user that reacted to a message in discord.js你如何让每个对 discord.js 中的消息做出反应的用户
【发布时间】:2020-05-17 08:18:35
【问题描述】:

我正在尝试获取对消息做出反应的每个用户的用户 ID 或等效项。我的代码看起来像这样,在我收到的输出中,我可以看到用户 ID。但我不知道如何抓住它们。有任何想法吗?我已经尝试过诸如 collection.users 之类的东西,但似乎没有任何效果。

这是我的代码,

const sumSeconds = 5;
const filter = reaction => {
      return ['????'].includes(reaction.emoji.name);
    }
    message.channel.send("React with ???? for a chance to win").then( message => {
      message.react("????");
      message.awaitReactions(filter,{max:50,time:sumSeconds*1000}).then(collection => {
        console.log(collection);
      }).catch();
    }).catch();

这是我打印时集合输出的内容

Collection [Map] {
  '????' => MessageReaction {
    message: Message {
      channel: [TextChannel],
      deleted: false,
      id: '672835948395216429',
      type: 'DEFAULT',
      content: 'React with ???? for a chance to win',
      author: [ClientUser],
      member: [GuildMember],
      pinned: false,
      tts: false,
      nonce: null,
      system: false,
      embeds: [],
      attachments: Collection [Map] {},
      createdTimestamp: 1580486989843,
      editedTimestamp: null,
      reactions: [Collection [Map]],
      mentions: [MessageMentions],
      webhookID: null,
      hit: null,
      _edits: []
    },
    me: true,
    count: 2,
    users: Collection [Map] {
      '671732735845016837' => [ClientUser],
      '181250039684617312' => [User]
    },
    _emoji: ReactionEmoji { reaction: [Circular], name: '????', id: null }
  }
}

我要提取的是这部分

users: Collection [Map] {
      '671732735845016837' => [ClientUser],
      '181250039684617312' => [User]
    }

请帮帮忙:

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    你必须使用collection.first().users:

    const sumSeconds = 5;
    const filter = reaction => {
          return ['?'].includes(reaction.emoji.name);
    };
    message.channel.send("React with ? for a chance to win").then( message => {
          message.react("?");
          message.awaitReactions(filter,{max:50,time:sumSeconds*1000}).then(collection => {
            console.log(collection.first().users); // Collection of users
          }).catch(() => {});
    }).catch(() => {});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 2018-04-03
      • 2021-05-14
      • 1970-01-01
      • 2021-07-02
      • 2021-06-24
      • 2020-09-07
      相关资源
      最近更新 更多