From 6515809dae10aa24de5da4657540f0111926a29b Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Mon, 21 Sep 2020 17:03:34 +0100 Subject: [PATCH] fix(GuildMemberManager): options.roles on 'prune' --- src/managers/GuildMemberManager.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/managers/GuildMemberManager.js b/src/managers/GuildMemberManager.js index 8072374bef6d..f11ae2c95c1a 100644 --- a/src/managers/GuildMemberManager.js +++ b/src/managers/GuildMemberManager.js @@ -161,19 +161,22 @@ class GuildMemberManager extends BaseManager { * .then(pruned => console.log(`I just pruned ${pruned} people!`)) * .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'); - const query = new URLSearchParams(); - query.set('days', days); - query.set('compute_prune_count', count); + const query = { days }; + const resolvedRoles = []; for (const role of roles) { const resolvedRole = this.guild.roles.resolveID(role); if (!resolvedRole) { 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; @@ -182,13 +185,12 @@ class GuildMemberManager extends BaseManager { 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); + return endpoint + .post({ + data: { ...query, compute_prune_count }, + reason, + }) + .then(data => data.pruned); } /**