mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
fix(GuildMemberManager): options.roles on 'prune' (#4838)
This commit is contained in:
@@ -162,19 +162,22 @@ class GuildMemberManager extends BaseManager {
|
|||||||
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
prune({ days = 7, dry = false, count = true, roles = [], reason } = {}) {
|
prune({ days = 7, dry = false, count: compute_prune_count = true, roles = [], reason } = {}) {
|
||||||
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
||||||
|
|
||||||
const query = new URLSearchParams();
|
const query = { days };
|
||||||
query.set('days', days);
|
const resolvedRoles = [];
|
||||||
query.set('compute_prune_count', count);
|
|
||||||
|
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
const resolvedRole = this.guild.roles.resolveID(role);
|
const resolvedRole = this.guild.roles.resolveID(role);
|
||||||
if (!resolvedRole) {
|
if (!resolvedRole) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array of Roles or Snowflakes', true));
|
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array of Roles or Snowflakes', true));
|
||||||
}
|
}
|
||||||
query.append('include_roles', role);
|
resolvedRoles.push(resolvedRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resolvedRoles.length) {
|
||||||
|
query.include_roles = dry ? resolvedRoles.join(',') : resolvedRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = this.client.api.guilds(this.guild.id).prune;
|
const endpoint = this.client.api.guilds(this.guild.id).prune;
|
||||||
@@ -183,13 +186,12 @@ class GuildMemberManager extends BaseManager {
|
|||||||
return endpoint.get({ query, reason }).then(data => data.pruned);
|
return endpoint.get({ query, reason }).then(data => data.pruned);
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = [...query.entries()].reduce((acc, [k, v]) => {
|
return endpoint
|
||||||
if (k === 'include_roles') v = (acc[k] || []).concat(v);
|
.post({
|
||||||
acc[k] = v;
|
data: { ...query, compute_prune_count },
|
||||||
return acc;
|
reason,
|
||||||
}, {});
|
})
|
||||||
|
.then(data => data.pruned);
|
||||||
return endpoint.post({ data: body, reason }).then(data => data.pruned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user