diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index a68fcf2..0faad7c 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -73,6 +73,28 @@ class RoleManager extends CachedManager { return id ? roles.get(id) ?? null : roles; } + /** + * Fetches the member counts for each role in the guild. + * @returns {Promise>} + */ + async fetchMemberCounts() { + const data = await this.client.api.guilds(this.guild.id).roles('member-counts').get(); + + return data; + } + + /** + * Fetches the member ids for a role in the guild. + * This only returns 100 member ids + * @param {RoleResolvable} id The role to fetch member ids for + * @returns {Promise} + */ + async fetchMemberIds(id) { + const data = await this.client.api.guilds(this.guild.id).roles(id, 'member-ids').get(); + + return data; + } + /** * Data that can be resolved to a Role object. This can be: * * A Role diff --git a/src/structures/Role.js b/src/structures/Role.js index b4e85b8..5748b63 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -449,6 +449,15 @@ class Role extends Base { return this; } + /** + * Fetches the member ids for this role in the guild. + * This only returns 100 member ids + * @returns {Promise} + */ + fetchMemberIds() { + return this.guild.roles.fetchMemberIds(this.id); + } + /** * A link to the role's icon * @param {StaticImageURLOptions} [options={}] Options for the image URL diff --git a/typings/index.d.ts b/typings/index.d.ts index 0a840e5..0457c56 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2912,6 +2912,7 @@ export class Role extends Base { public setIcon(icon: BufferResolvable | Base64Resolvable | EmojiResolvable | null, reason?: string): Promise; public setPosition(position: number, options?: SetRolePositionOptions): Promise; public setUnicodeEmoji(unicodeEmoji: string | null, reason?: string): Promise; + public fetchMemberIds(): Promise; public toJSON(): unknown; public toString(): RoleMention; @@ -4709,6 +4710,8 @@ export class RoleManager extends CachedManager public setPosition(role: RoleResolvable, position: number, options?: SetRolePositionOptions): Promise; public setPositions(rolePositions: readonly RolePosition[]): Promise; public comparePositions(role1: RoleResolvable, role2: RoleResolvable): number; + public fetchMemberCounts(): Promise>; + public fetchMemberIds(role: RoleResolvable): Promise; } export class StageInstanceManager extends CachedManager {