mirror of
https://github.com/danbulant/discord.js
synced 2026-05-27 22:11:53 +00:00
feat(GuildMemberStore) add options.count to prune (#3189)
* add GuildMemberStore#prune(options.count) * typings: proper typings for null return value
This commit is contained in:
parent
39115c8acc
commit
7b531648e0
2 changed files with 10 additions and 3 deletions
|
|
@ -106,11 +106,13 @@ class GuildMemberStore extends DataStore {
|
|||
|
||||
/**
|
||||
* Prunes members from the guild based on how long they have been inactive.
|
||||
* <info>It's recommended to set options.count to `false` for large guilds.</info>
|
||||
* @param {Object} [options] Prune options
|
||||
* @param {number} [options.days=7] Number of days of inactivity required to kick
|
||||
* @param {boolean} [options.dry=false] Get number of users that will be kicked, without actually kicking them
|
||||
* @param {boolean} [options.count=true] Whether or not to return the number of users that have been kicked.
|
||||
* @param {string} [options.reason] Reason for this prune
|
||||
* @returns {Promise<number>} The number of members that were/will be kicked
|
||||
* @returns {Promise<number|null>} The number of members that were/will be kicked
|
||||
* @example
|
||||
* // See how many members will be pruned
|
||||
* guild.members.prune({ dry: true })
|
||||
|
|
@ -122,9 +124,12 @@ class GuildMemberStore extends DataStore {
|
|||
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
prune({ days = 7, dry = false, reason } = {}) {
|
||||
prune({ days = 7, dry = false, count = true, reason } = {}) {
|
||||
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
||||
return this.client.api.guilds(this.guild.id).prune[dry ? 'get' : 'post']({ query: { days }, reason })
|
||||
return this.client.api.guilds(this.guild.id).prune[dry ? 'get' : 'post']({ query: {
|
||||
days,
|
||||
compute_prune_count: count,
|
||||
}, reason })
|
||||
.then(data => data.pruned);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
|
|
@ -1430,6 +1430,7 @@ declare module 'discord.js' {
|
|||
public fetch(options: UserResolvable | FetchMemberOptions): Promise<GuildMember>;
|
||||
public fetch(): Promise<GuildMemberStore>;
|
||||
public fetch(options: FetchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
|
||||
public prune(options: GuildPruneMembersOptions & { dry?: false, count: false }): Promise<null>;
|
||||
public prune(options?: GuildPruneMembersOptions): Promise<number>;
|
||||
public unban(user: UserResolvable, reason?: string): Promise<User>;
|
||||
}
|
||||
|
|
@ -1901,6 +1902,7 @@ declare module 'discord.js' {
|
|||
type GuildResolvable = Guild | Snowflake;
|
||||
|
||||
interface GuildPruneMembersOptions {
|
||||
count?: boolean;
|
||||
days?: number;
|
||||
dry?: boolean;
|
||||
reason?: string;
|
||||
|
|
|
|||
Loading…
Reference in a new issue