GuildMember.fetch loading 15s-30min but fetching manually using REST works instantly

Hey, I am currently having the issue that on very busy servers (100-800k members), my Discord bot is having issues fetching members properly. Executing
member.fetch()
member.fetch()
sometimes takes ages while
fetch(`${apiURL}/guilds/${guildId}/members/${memberId}`)
fetch(`${apiURL}/guilds/${guildId}/members/${memberId}`)
resolves instantly with a rate limit bucket of 4 of 5 left. Is this an issue with discord.js' internal rate limit handling or am I missing something? Any help is appreciated!
17 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Syjalo
Syjalo2y ago
This fetching all members through the Gateway. Members are sent with chunks by 1000 in each. That's why it can take a long time on large servers.
await <Guild>.members.fetch();
await <Guild>.members.fetch();
This fetching only 1 member through the REST API with the route that you specified in your question.
await <Guild>.members.fetch('id');
await <Guild>.members.fetch('id');
Xge
XgeOP2y ago
I am fetching a single member, not multiple A server reported that they are having issues with banning, warning, muting users but also with the userinfo command. So I checked if my bot got rate limited fetching users using client.users.fetch(userId) but that resolved instantly. So I did guild.members.fetch({ user: userId, force: true }) and it did not resolve after a few seconds. While this operation was still running, I could easily fetch the member using node-fetch("/api/.../members/userId"). After ~8 minutes, the guild.members.fetch thingy finally resolved. This fixes itself after a while but mostly happens when the server is very active I also debugged the guild.members.fetch function in the discord.js code and it was stuck at
const data = await this.client.api.guilds(this.guild.id).members(user).get();
const data = await this.client.api.guilds(this.guild.id).members(user).get();
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xge
XgeOP2y ago
I did use force: true and the node-fetch package does not cache data to my knowledge.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xge
XgeOP2y ago
Yeah, but discord.js took 8 minutes while node-fetch resolves instantly But why are the rate limit headers are then saying that I have 4 of 5 requests left when using node-fetch? Shouldn't it be anything less than 4 since discord.js is fetching other members right now? Alright. Any way to see how many members are currently in the fetch queue?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Syjalo
Syjalo2y ago
btw do you use prefix commands or slash commands?
Xge
XgeOP2y ago
For testing purposes I force fetched a single member. But usually I don't use the force option
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Xge
XgeOP2y ago
My bot supports both, the server reported the issue used slash commands. Is there any way to deal with this on a large server?
Syjalo
Syjalo2y ago
So what user do you fetch? Users from the user option are always resolved.
Xge
XgeOP2y ago
I am not really fetching that often.. just when using moderation commands which are used a lot in the server. But only members who already wrote something in the past few minutes are usually punished, so they should be in the cache already. Maybe as a side note: This server did not use the main bot but a custom branded version of it with the Presence Intent enabled, so almost all members are cached. Just checked and the custom branded bot which is just in this single server currently has 160k members in its cache. Just checked, I always do member.fetch(false) or guild.members.fetch(id) The only time I am using member.fetch(false) is when assigning roles through Reaction Roles as it waits 5 seconds to assign the roles and I want to make sure it is still in the cache (so the member did not leave). But the server that is having the issues is not using Reaction Roles at all. Member fetch rejected / member not in cache -> do nothing Role could not be assigned -> Tell server admins that my bot is unable to add roles because of err.message But this is not the thing causing issues here. I am still trying to figure out why it gets stuck on fetching a member that is already cached when using guild.members.fetch(id) with force: false Nope 13.11.0 Is there any way to check what fetch requests are queued? So the next time it happens, I can check if a full queue is the issue?
chewie
chewie2y ago
client.rest.requestManager.handlers is a collection of handlers, each having a property called #asyncQueue, but idk how far you will get with that time to get rid of v13
Xge
XgeOP2y ago
Hey again, turns out that it was not the member fetching but member editing that caused the delay when using moderation commands. The server that is having these issues is currently getting +10-30k members every day which is also the reason for their high use of moderation commands. Is Discord increasing rate limits for editing members (for adding/removing roles or timeouts) in large servers? Thank you all for the help btw.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server