您如何获得对discord.js中的消息有反应的每个用户

时间:2020-01-31 16:21:54

标签: node.js discord discord.js

我正在尝试获取对消息做出反应的每个用户的用户名或等效名称。我的代码看起来像这样,在我收到的输出中,我可以看到用户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]
    }

请帮助c:

1 个答案:

答案 0 :(得分:0)

您必须使用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(() => {});