mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
feat: backport after and before parameter when fetching a reaction's users (#2218)
Commits: -f40a5e9f88-5cd42695ae
This commit is contained in:
@@ -914,8 +914,10 @@ class RESTMethods {
|
|||||||
.then(() => message);
|
.then(() => message);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessageReactionUsers(message, emoji, limit = 100) {
|
getMessageReactionUsers(message, emoji, options) {
|
||||||
return this.rest.makeRequest('get', Endpoints.Message(message).Reaction(emoji, limit), true);
|
const queryString = (querystring.stringify(options).match(/[^=&?]+=[^=&?]+/g) || []).join('&');
|
||||||
|
|
||||||
|
return this.rest.makeRequest('get', `${Endpoints.Message(message).Reaction(emoji)}?${queryString}`, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
getApplication(id) {
|
getApplication(id) {
|
||||||
|
|||||||
@@ -72,19 +72,20 @@ class MessageReaction {
|
|||||||
/**
|
/**
|
||||||
* Fetch all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
|
* Fetch all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
|
||||||
* @param {number} [limit=100] The maximum amount of users to fetch, defaults to 100
|
* @param {number} [limit=100] The maximum amount of users to fetch, defaults to 100
|
||||||
|
* @param {Object} [options] Options to fetch users
|
||||||
|
* @param {Snowflake} [options.before] Limit fetching users to those with an id lower than the supplied id
|
||||||
|
* @param {Snowflake} [options.after] Limit fetching users to those with an id greater than the supplied id
|
||||||
* @returns {Promise<Collection<Snowflake, User>>}
|
* @returns {Promise<Collection<Snowflake, User>>}
|
||||||
*/
|
*/
|
||||||
fetchUsers(limit = 100) {
|
fetchUsers(limit = 100, { after, before } = {}) {
|
||||||
const message = this.message;
|
const message = this.message;
|
||||||
return message.client.rest.methods.getMessageReactionUsers(
|
return message.client.rest.methods.getMessageReactionUsers(
|
||||||
message, this.emoji.identifier, limit
|
message, this.emoji.identifier, { after, before, limit }
|
||||||
).then(users => {
|
).then(users => {
|
||||||
this.users = new Collection();
|
|
||||||
for (const rawUser of users) {
|
for (const rawUser of users) {
|
||||||
const user = this.message.client.dataManager.newUser(rawUser);
|
const user = this.message.client.dataManager.newUser(rawUser);
|
||||||
this.users.set(user.id, user);
|
this.users.set(user.id, user);
|
||||||
}
|
}
|
||||||
this.count = this.users.size;
|
|
||||||
return this.users;
|
return this.users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,8 +187,8 @@ const Endpoints = exports.Endpoints = {
|
|||||||
toString: () => mbase,
|
toString: () => mbase,
|
||||||
reactions: `${mbase}/reactions`,
|
reactions: `${mbase}/reactions`,
|
||||||
ack: `${mbase}/ack`,
|
ack: `${mbase}/ack`,
|
||||||
Reaction: (emoji, limit) => {
|
Reaction: emoji => {
|
||||||
const rbase = `${mbase}/reactions/${emoji}${limit ? `?limit=${limit}` : ''}`;
|
const rbase = `${mbase}/reactions/${emoji}`;
|
||||||
return {
|
return {
|
||||||
toString: () => rbase,
|
toString: () => rbase,
|
||||||
User: userID => `${rbase}/${userID}`,
|
User: userID => `${rbase}/${userID}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user