Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GuildMemberManager): add 'list' method #6403

Merged
merged 7 commits into from Aug 12, 2021
18 changes: 18 additions & 0 deletions src/managers/GuildMemberManager.js
Expand Up @@ -205,6 +205,24 @@ class GuildMemberManager extends CachedManager {
return data.reduce((col, member) => col.set(member.user.id, this._add(member, cache)), new Collection());
}

/**
* Options used for listing guild members.
* @typedef {Object} GuildListMembersOptions
* @property {Snowflake} [after] Limit fetching members to those with an id greater than the supplied id
* @property {number} [limit=1] Maximum number of members to list
* @property {boolean} [cache=true] Whether or not to cache the fetched member(s)
*/

/**
* Lists up to 1000 members of the guild.
* @param {GuildListMembersOptions} [options] Options for listing members
* @returns {Promise<Collection<Snowflake, GuildMember>>}
*/
async list({ after, limit = 1, cache = true } = {}) {
BenjammingKirby marked this conversation as resolved.
Show resolved Hide resolved
const data = await this.client.api.guilds(this.guild.id).members.get({ query: { after, limit } });
return data.reduce((col, member) => col.set(member.user.id, this._add(member, cache)), new Collection());
}

/**
* Edits a member of the guild.
* <info>The user must be a member of the guild</info>
Expand Down
9 changes: 8 additions & 1 deletion typings/index.d.ts
Expand Up @@ -130,7 +130,7 @@ import {
RawWelcomeChannelData,
RawWelcomeScreenData,
RawWidgetData,
RawWidgetMemberData
RawWidgetMemberData,
} from './rawDataTypes';

//#region Classes
Expand Down Expand Up @@ -2474,6 +2474,7 @@ export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, Gu
): Promise<GuildMember>;
public fetch(options?: FetchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
public kick(user: UserResolvable, reason?: string): Promise<GuildMember | User | Snowflake>;
public list(options?: GuildListMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
public prune(options: GuildPruneMembersOptions & { dry?: false; count: false }): Promise<null>;
public prune(options?: GuildPruneMembersOptions): Promise<number>;
public search(options: GuildSearchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
Expand Down Expand Up @@ -3812,6 +3813,12 @@ export interface GuildSearchMembersOptions {
cache?: boolean;
}

export interface GuildListMembersOptions {
after?: Snowflake;
limit?: number;
cache?: boolean;
}

export type GuildTemplateResolvable = string;

export type GuildVoiceChannelResolvable = VoiceChannel | StageChannel | Snowflake;
Expand Down