Merge pull request #1592 from Lixqa/main
Added the ability to fetch role member counts and member ids for single roles
This commit is contained in:
@@ -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<Record<Snowflake, number>>}
|
||||
*/
|
||||
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.
|
||||
* <info>This only returns 100 member ids</info>
|
||||
* @param {RoleResolvable} id The role to fetch member ids for
|
||||
* @returns {Promise<Snowflake[]>}
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -449,6 +449,15 @@ class Role extends Base {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the member ids for this role in the guild.
|
||||
* <info>This only returns 100 member ids</info>
|
||||
* @returns {Promise<Snowflake[]>}
|
||||
*/
|
||||
fetchMemberIds() {
|
||||
return this.guild.roles.fetchMemberIds(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* A link to the role's icon
|
||||
* @param {StaticImageURLOptions} [options={}] Options for the image URL
|
||||
|
||||
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@@ -2912,6 +2912,7 @@ export class Role extends Base {
|
||||
public setIcon(icon: BufferResolvable | Base64Resolvable | EmojiResolvable | null, reason?: string): Promise<Role>;
|
||||
public setPosition(position: number, options?: SetRolePositionOptions): Promise<Role>;
|
||||
public setUnicodeEmoji(unicodeEmoji: string | null, reason?: string): Promise<Role>;
|
||||
public fetchMemberIds(): Promise<Snowflake[]>;
|
||||
public toJSON(): unknown;
|
||||
public toString(): RoleMention;
|
||||
|
||||
@@ -4709,6 +4710,8 @@ export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
|
||||
public setPosition(role: RoleResolvable, position: number, options?: SetRolePositionOptions): Promise<Role>;
|
||||
public setPositions(rolePositions: readonly RolePosition[]): Promise<Guild>;
|
||||
public comparePositions(role1: RoleResolvable, role2: RoleResolvable): number;
|
||||
public fetchMemberCounts(): Promise<Record<Snowflake, number>>;
|
||||
public fetchMemberIds(role: RoleResolvable): Promise<Snowflake[]>;
|
||||
}
|
||||
|
||||
export class StageInstanceManager extends CachedManager<Snowflake, StageInstance, StageInstanceResolvable> {
|
||||
|
||||
Reference in New Issue
Block a user