Discord.js: Issues with <guild>.members.prune()

Created on 20 Sep 2020  Â·  10Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
When using the prune method, with correct roles ids and the dry option true, it always returns 0
You can see below that I tried to fetch all the members, but it's not the problem ^^.
Include a reproducible code sample here, if possible:

await message.guild.members.fetch({force: true})
        message.guild.members.prune({days: 30, roles: ["657172882677432321", "657172932040327178", "657172954760740876", "657172981960802304", "691558625608597504"],dry: true })
        .then(pruned => console.log(pruned))
        .catch(console.error);

Further details:

  • discord.js version: 12.3.1
  • Node.js version: 12.18.3
  • Operating system: Raspbian 10
  • Priority this issue should have – please be realistic and elaborate if possible:
    Well, i don't really know if the entire prune is broken, or only with the dry option.

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
  • [ ] I have also tested the issue on latest master, commit hash:
REST bug

All 10 comments

I cannot seem to reproduce it exactly. I am using discord.js 12.3.1 with nodejs 14.11.0 on Ubuntu 18.04.3 LTS. No partials, nor gateway intents.

image

While i can not reproduce 0 (which i think is just coincidence) i can reproduce the role parameter being ignored. If i input the same "query" through discords UI the dry run ("this action will prune X members") changes if i add a specific role. If I do the according request with the bot the number stays constant, without taking additional roles into consideration, will investigate shortly

Not exactly sure, but could this be an issue?
https://github.com/discordjs/discord.js/blob/master/src/managers/GuildMemberManager.js#L176
the discord docs say you must provide string; comma-delimited array of snowflakes but when calling toString() on the query it isn't a comma-delimited string. compute_prune_count=true&days=1&include_roles=roleone&include_roles=roletwo

image

It's a bit deeper than that:

https://github.com/discordjs/discord.js/blob/56e8ef2d38633154540748acb64f4c1305fcc6d3/src/rest/APIRequest.js#L21-L24

Object.entries(options.query) does not have the expected results when a URLSearchParams instance is passed here and results in [] as the base array the filtering is being done on. This causes a complete disregard for any and all parameters that are passed as query options, resulting in the request https://discord.com/api/v7/guilds/:id:/prune to be made.

GuildMemberManager#prune seems to be the only occasion where URLSearchParams are used here, in all other cases plain objects are used.

This was introduced in https://github.com/discordjs/discord.js/pull/4143 (https://github.com/discordjs/discord.js/pull/4143/commits/9d9e821c70a8a183ac5defbaba0cb20f567eaed0) by only partially applying provided feedback

the discord docs say you must provide string; comma-delimited array of snowflakes but when calling toString() on the query it isn't a comma-delimited string. compute_prune_count=true&days=1&include_roles=roleone&include_roles=roletwo

while correct, this is also what the client does, despite it not being in spec for the API documentation (though the client by now uses v8, where this might have changed)

I can "confirm" that it doesn't take count of the roles we pass. I tried to remove all the roles of an afk member, and

<guild>.members.prune({dry: true})  

returned 1

@izexi is writing a fix for the next release

When will be the next release ^^ ? Or is there a workaround for the moment ?

Since this is deeply rooted in our request handling there is no work around for this yet but making the raw API call through a normal request (not even the internal methodology, because it's in the query builder). I can not give you an estimate on when the next release will happen, you can watch the pull request to get notified when it's merged (once it's opened github will automatically reference it in this thread)

its a problem with the code try to run it and tell me the error

@Starbors Thanks but this is already being solved. And,I don’t have any errors, and if I did, I wouldn’t create an issue for that

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blumlaut picture Blumlaut  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

smchase picture smchase  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments