Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with <guild>.members.prune() #4834

Closed
1 task
siim0n opened this issue Sep 20, 2020 · 10 comments · Fixed by #4838
Closed
1 task

Issues with <guild>.members.prune() #4834

siim0n opened this issue Sep 20, 2020 · 10 comments · Fixed by #4838

Comments

@siim0n
Copy link

siim0n commented Sep 20, 2020

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:
@siim0n siim0n changed the title Issues with <guild>.prune() Issues with <guild>.members.prune() Sep 20, 2020
@BannerBomb
Copy link
Contributor

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

@almostSouji
Copy link
Member

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

@BannerBomb
Copy link
Contributor

BannerBomb commented Sep 21, 2020

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

@almostSouji
Copy link
Member

almostSouji commented Sep 21, 2020

It's a bit deeper than that:

const query = Object.entries(options.query)
.filter(([, value]) => ![null, 'null', 'undefined'].includes(value) && typeof value !== 'undefined')
.flatMap(([key, value]) => (Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]));
queryString = new URLSearchParams(query).toString();

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 #4143 (9d9e821) 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)

@siim0n
Copy link
Author

siim0n commented Sep 21, 2020

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

@almostSouji
Copy link
Member

@izexi is writing a fix for the next release

@siim0n
Copy link
Author

siim0n commented Sep 21, 2020

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

@almostSouji
Copy link
Member

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)

@Starbors
Copy link

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

@siim0n
Copy link
Author

siim0n commented Sep 29, 2020

@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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants