discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

guild.members.fetch times out when fetching more than one users (when at least 1 id is not numbers) #6022

Closed ggggg closed 3 years ago

ggggg commented 3 years ago

Please describe the problem you are having in as much detail as possible: I don't know if this is an API issue or discord.js, please let me know if I should report it somewhere else.

When entering anything that's not a number id, the API times out, instead of throwing an error/ignoring the id. The bot disconnects and reconnects before throwing the timeout error.

However, it works if I enter an invalid number ID.

Include a reproducible code sample here, if possible:

// doesnt work
guild.members.fetch({user: ['202510746058358784', '330357883713748994', 'abcd']})
// work
guild.members.fetch({user: ['202510746058358784', '330357883713748994', '1234']})

Output:

Error [GUILD_MEMBERS_TIMEOUT]: Members didn't arrive in time.
    at /path/to/project/node_modules/discord.js/src/managers/GuildMemberManager.js:385:16
    at Timeout._onTimeout (/path/to/project/discord.js/src/client/BaseClient.js:82:7)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  [Symbol(code)]: 'GUILD_MEMBERS_TIMEOUT'
}

Further details:

Relevant client options:

DTrombett commented 3 years ago

It's a Discord API error so we can't really do anything about this. You should ask in DDev server probably. It also invalidated my bot session...

ggggg commented 3 years ago

Alright, I sent it on the server but I believe the devs are on break until the 12th so I might have to post it again after the 12th.

Regardless of the API I think it is possible to add a number check on https://github.com/discordjs/discord.js/blob/ec06ba7ad04d21e61f3e734e489607a1a5ab3568/src/managers/GuildMemberManager.js#L129 or on https://github.com/discordjs/discord.js/blob/ec06ba7ad04d21e61f3e734e489607a1a5ab3568/src/managers/GuildMemberManager.js#L346 to solve this issue.

Something like:

foreach id in users
    if id is not number
        throw some error
iCrawl commented 3 years ago

I would write this off as user error.

We probably can check, but it seems redundant if the developer itself could just sanitize and check the input before passing it to the library.

ggggg commented 3 years ago

Before I noticed this issue I was under the impression it would be treated the same as an invalid ID, would be nice to let the developer know, but you are right; its not needed per say and the discord API should just respond with error code 400 or something instead of time out the application.

I guess I should wait for the discord developers to fix this issue. Thank you @iCrawl and @DTrombett for explaining!