Add reaction fetching of users

This commit is contained in:
Amish Shah
2016-10-27 16:58:06 +01:00
parent 8e505ed349
commit dd9c291508
3 changed files with 45 additions and 0 deletions

View File

@@ -108,6 +108,28 @@ class MessageReaction {
const message = this.message;
return message.client.rest.methods.removeMessageReaction(message.channel.id, message.id, this.emoji.identifier);
}
/**
* Fetch all the users that gave this reaction. Resolves with a collection of users,
* mapped by their IDs.
* @returns {Promise<Collection<string, User>>}
*/
fetchUsers() {
const message = this.message;
return new Promise((resolve, reject) => {
message.client.rest.methods.getMessageReactionUsers(message.channel.id, message.id, this.emoji.identifier)
.then(users => {
this.users = new Collection();
for (const rawUser of users) {
const user = this.message.client.dataManager.newUser(rawUser);
this.users.set(user.id, user);
}
this.count = this.users.size;
resolve(this.users);
})
.catch(reject);
});
}
}
module.exports = MessageReaction;