mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Add reaction fetching of users
This commit is contained in:
@@ -751,6 +751,13 @@ class RESTMethods {
|
|||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMessageReactionUsers(channelID, messageID, emoji, limit = 100) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('get', Constants.Endpoints.messageReaction(channelID, messageID, emoji, limit), true)
|
||||||
|
.then(resolve, reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RESTMethods;
|
module.exports = RESTMethods;
|
||||||
|
|||||||
@@ -108,6 +108,28 @@ class MessageReaction {
|
|||||||
const message = this.message;
|
const message = this.message;
|
||||||
return message.client.rest.methods.removeMessageReaction(message.channel.id, message.id, this.emoji.identifier);
|
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;
|
module.exports = MessageReaction;
|
||||||
|
|||||||
@@ -187,3 +187,19 @@ client.on('messageReactionRemove', (reaction, user) => {
|
|||||||
if (reaction.message.channel.id !== '222086648706498562') return;
|
if (reaction.message.channel.id !== '222086648706498562') return;
|
||||||
reaction.message.channel.sendMessage(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
reaction.message.channel.sendMessage(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('message', m => {
|
||||||
|
if (m.content.startsWith('#reactions')) {
|
||||||
|
const mID = m.content.split(' ')[1];
|
||||||
|
m.channel.fetchMessage(mID).then(rM => {
|
||||||
|
for (const reaction of rM.reactions.values()) {
|
||||||
|
reaction.fetchUsers().then(users => {
|
||||||
|
m.channel.sendMessage(
|
||||||
|
`The following gave that message ${reaction.emoji}:\n` +
|
||||||
|
`${users.map(u => u.username).map(t => `- ${t}`).join('\n')}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user