Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ declare namespace Eris {
limit?: number;
userID?: string;
}
interface GetGuildBansOptions {
after?: string;
before?: string;
limit?: number;
}
interface GetPruneOptions {
days?: number;
includeRoles?: string[];
Expand All @@ -883,6 +888,10 @@ declare namespace Eris {
users: User[];
webhooks: Webhook[];
}
interface GuildBan {
reason?: string;
user: User;
}
interface GuildOptions {
afkChannelID?: string;
afkTimeout?: number;
Expand Down Expand Up @@ -2360,8 +2369,8 @@ declare namespace Eris {
getGuildAuditLog(guildID: string, options?: GetGuildAuditLogOptions): Promise<GuildAuditLog>;
/** @deprecated */
getGuildAuditLogs(guildID: string, limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
getGuildBan(guildID: string, userID: string): Promise<{ reason?: string; user: User }>;
getGuildBans(guildID: string): Promise<{ reason?: string; user: User }[]>;
getGuildBan(guildID: string, userID: string): Promise<GuildBan>;
getGuildBans(guildID: string, options?: GetGuildBansOptions): Promise<GuildBan[]>;
getGuildCommand(guildID: string, commandID: string): Promise<ApplicationCommand>;
getGuildCommandPermissions(guildID: string): Promise<GuildApplicationCommandPermissions[]>;
getGuildCommands(guildID: string): Promise<ApplicationCommand[]>;
Expand Down Expand Up @@ -2735,8 +2744,8 @@ declare namespace Eris {
getAuditLog(options?: GetGuildAuditLogOptions): Promise<GuildAuditLog>;
/** @deprecated */
getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
getBan(userID: string): Promise<{ reason?: string; user: User }>;
getBans(): Promise<{ reason?: string; user: User }[]>;
getBan(userID: string): Promise<GuildBan>;
getBans(options?: GetGuildBansOptions): Promise<GuildBan[]>;
getCommand(commandID: string): Promise<ApplicationCommand>;
getCommandPermissions(): Promise<GuildApplicationCommandPermissions[]>;
getCommands(): Promise<ApplicationCommand[]>;
Expand Down
42 changes: 34 additions & 8 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2332,15 +2332,41 @@ class Client extends EventEmitter {
/**
* Get the ban list of a guild
* @arg {String} guildID The ID of the guild
* @returns {Promise<Array<Object>>} Resolves with an array of {reason: String, user: User}
*/
getGuildBans(guildID) {
return this.requestHandler.request("GET", Endpoints.GUILD_BANS(guildID), true).then((bans) => {
bans.forEach((ban) => {
ban.user = new User(ban.user, this);
});
return bans;
* @arg {Object} [options] Options for the request
* @arg {String} [options.after] Only get users after given user ID
* @arg {String} [options.before] Only get users before given user ID
* @arg {Number} [options.limit=1000] The maximum number of users to return
* @returns {Promise<Array<Object>>} Resolves with an array of { reason: String, user: User }
*/
async getGuildBans(guildID, options = {}) {
const bans = await this.requestHandler.request("GET", Endpoints.GUILD_BANS(guildID), true, {
after: options.after,
before: options.before,
limit: Math.min(options.limit, 1000)
});

bans.forEach((ban) => {
ban.user = this.users.update(ban.user, this);
});

if(options.limit && options.limit > 1000 && bans.length >= 1000) {
if(options.before) {
options.after = undefined;
options.before = bans[0].user.id;
} else {
options.after = bans[bans.length - 1].user.id;
}

const page = await this.getGuildBans(guildID, {
after: options.after,
before: options.before,
limit: options.limit - bans.length
});

bans.push(...page);
}

return bans;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,14 @@ class Guild extends Base {

/**
* Get the ban list of the guild
* @returns {Promise<Array<Object>>} Resolves with an array of {reason: String, user: User}
*/
getBans() {
return this._client.getGuildBans.call(this._client, this.id);
* @arg {Object} [options] Options for the request
* @arg {String} [options.after] Only get users after given user ID
* @arg {String} [options.before] Only get users before given user ID
* @arg {Number} [options.limit=1000] The maximum number of users to return
* @returns {Promise<Array<Object>>} Resolves with an array of { reason: String, user: User }
*/
getBans(options) {
return this._client.getGuildBans.call(this._client, this.id, options);
}

/**
Expand Down