mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat(GuildMemberManager#prune): roles query param (#4142)
Co-authored-by: izexi <43889168+izexi@users.noreply.github.com> Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: kyranet <kyradiscord@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: Noel <icrawltogo@gmail.com>
This commit is contained in:
@@ -142,6 +142,7 @@ class GuildMemberManager extends BaseManager {
|
|||||||
* @param {number} [options.days=7] Number of days of inactivity required to kick
|
* @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.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 {boolean} [options.count=true] Whether or not to return the number of users that have been kicked.
|
||||||
|
* @param {RoleResolvable[]} [options.roles=[]] Array of roles to bypass the "...and no roles" constraint when pruning
|
||||||
* @param {string} [options.reason] Reason for this prune
|
* @param {string} [options.reason] Reason for this prune
|
||||||
* @returns {Promise<number|null>} The number of members that were/will be kicked
|
* @returns {Promise<number|null>} The number of members that were/will be kicked
|
||||||
* @example
|
* @example
|
||||||
@@ -154,19 +155,40 @@ class GuildMemberManager extends BaseManager {
|
|||||||
* guild.members.prune({ days: 1, reason: 'too many people!' })
|
* guild.members.prune({ days: 1, reason: 'too many people!' })
|
||||||
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
|
* @example
|
||||||
|
* // Include members with a specified role
|
||||||
|
* guild.members.prune({ days: 7, roles: ['657259391652855808'] })
|
||||||
|
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
prune({ days = 7, dry = false, count = true, reason } = {}) {
|
prune({ days = 7, dry = false, count = true, roles = [], reason } = {}) {
|
||||||
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
||||||
return this.client.api
|
|
||||||
.guilds(this.guild.id)
|
const query = new URLSearchParams();
|
||||||
.prune[dry ? 'get' : 'post']({
|
query.set('days', days);
|
||||||
query: {
|
query.set('compute_prune_count', count);
|
||||||
days,
|
|
||||||
compute_prune_count: count,
|
for (const role of roles) {
|
||||||
},
|
const resolvedRole = this.guild.roles.resolveID(role);
|
||||||
reason,
|
if (!resolvedRole) {
|
||||||
})
|
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array of Roles or Snowflakes', true));
|
||||||
.then(data => data.pruned);
|
}
|
||||||
|
query.append('include_roles', role);
|
||||||
|
}
|
||||||
|
|
||||||
|
const endpoint = this.client.api.guilds(this.guild.id).prune;
|
||||||
|
|
||||||
|
if (dry) {
|
||||||
|
return endpoint.get({ query, reason }).then(data => data.pruned);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = [...query.entries()].reduce((acc, [k, v]) => {
|
||||||
|
if (k === 'include_roles') v = (acc[k] || []).concat(v);
|
||||||
|
acc[k] = v;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return endpoint.post({ data: body, reason }).then(data => data.pruned);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -2606,6 +2606,7 @@ declare module 'discord.js' {
|
|||||||
days?: number;
|
days?: number;
|
||||||
dry?: boolean;
|
dry?: boolean;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
|
roles?: RoleResolvable[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GuildWidgetData {
|
interface GuildWidgetData {
|
||||||
|
|||||||
Reference in New Issue
Block a user