diff --git a/packages/discord.js/src/managers/RoleManager.js b/packages/discord.js/src/managers/RoleManager.js index e17f4f46d..bf117b5d2 100644 --- a/packages/discord.js/src/managers/RoleManager.js +++ b/packages/discord.js/src/managers/RoleManager.js @@ -81,6 +81,17 @@ class RoleManager extends CachedManager { return this._add(data, cache); } + /** + * Fetches the member count of each role in the guild. + * This does not include the `@everyone` role. + * + * @returns {Promise>} A collection mapping role ids to their respective member counts. + */ + async fetchMemberCounts() { + const data = await this.client.rest.get(Routes.guildRoleMemberCounts(this.guild.id)); + return new Collection(Object.entries(data)); + } + /** * Data that can be resolved to a Role object. This can be: * - A Role diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 4d78d3d98..f418fdc89 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4723,6 +4723,7 @@ export class RoleManager extends CachedManager public botRoleFor(user: UserResolvable): Role | null; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; + public fetchMemberCounts(): Promise>; public create(options?: RoleCreateOptions): Promise; public edit(role: RoleResolvable, options: RoleEditOptions): Promise; public delete(role: RoleResolvable, reason?: string): Promise;