Discord.js: Error: Members didn't arrive in time.

Created on 12 Feb 2020  ·  17Comments  ·  Source: discordjs/discord.js

Discord bot not caching all members and giving wrong member count

Discord

Most helpful comment

As of 27/10/2020 (warned since October 7, 2020), Discord has started enforcing intents and developers are required to enable them for receiving certain gateway events. Read the guide on intents.

All 17 comments

This has been a recurring issue the past few days, it is not a library problem. There seems to be issues with the guild members chunk event not working properly. It is an API issue out of our control.

P.S.: you should not ignore the issue template 👀

It looks like Discord sends those packets (again), at least for me.

Same thing happening here

Same thing here

This has been happening consistently to me for a while now.

If it is a problem at Discord's end, I wonder if they broke something when rolling out intent support -- I know intents are meant to be optional right now, but maybe they're not as optional as they should be.

Given that fetching all members was the one intent that they planned on restricting, I don't think this is "broken" but we'd definitely need more information from you all to try to help determine a real cause. Probably most notably - how many guilds is your bot impacted by this issue in?

Of course, if you're all logging in with user tokens, then A) you shouldn't be anyway since its against ToS and B) this is expected behaviour for user accounts

When I do

await guild.members.fetch();

I'm getting the following error message:
[GUILD_MEMBERS_TIMEOUT]: Members didn't arrive in time.

My bot is connected to ~5,000 guilds, and this always happens on the same 4 guilds. I read this might have to do with large guilds, however they're not particularly large at 48, 134, 632, and 1078 members (logging with guild.memberCount). Any ideas what might be causing this and what I can do?

I tend to get this error a lot when fetching all the guild members but when it fails I fall back to the cache. However, I did notice something interesting.

Whenever I am getting this error (I print out the guild.memberCount() and the guild.members.cache.size) the difference between the member count and cache size is almost always 1 (highest I have seen is 3-4). This makes me feel like the fetch() isn't fully failing, and it might only be failing to fetch one or a few members.
image

It could also be that discord is returning the correct amount of members but discord.js is doing some checks behind the scene and expecting it to be equal to guild.memberCount but it's guild.memberCount is out of date.

Hitting the same issue today

Dito, hitting the same issue today.

As of 27/10/2020 (warned since October 7, 2020), Discord has started enforcing intents and developers are required to enable them for receiving certain gateway events. Read the guide on intents.

Extending Extroonie's comment above, this can be resolved by requesting the GUILD_MEMBERS intent.

Steps:
1a. Go to https://discord.com/developers/applications
1b. Select your application, move to the Bot tab in the sidebar
1c. Enable "server members intent"

  1. Make code changes (not required for the current version of Discord.js, will be required in the next major release, thanks @almostSouji )

Code (before):

const { Client } = require("discord.js");
const client = new Client();

Code (after):

const { Client, Intents } = require("discord.js");
const intents = new Intents([
    Intents.NON_PRIVILEGED, // include all non-privileged intents, would be better to specify which ones you actually need
    "GUILD_MEMBERS", // lets you request guild members (i.e. fixes the issue)
]);
const client = new Client({ ws: { intents } });

References:
https://discordjs.guide/popular-topics/intents.html#privileged-intents
https://discord.js.org/#/docs/main/stable/class/Intents

Edit: I made the mistake of referencing this issue in personal projects, would be appreciated if an admin removed the "added a commit that referenced this issue" comments below.

  1. Make code changes

No code changes needed. You don't need to necessarily provide the intents for version 12 of discord.js.
If you provide no intents to the Client constructor discord will just send all events for all intents (privileged intents require the toggle or explicit grant in case of bot verification (100+ servers). This will change in v13 where intents will be required.)


:gear: Privileged intents and what they mean for you
❯ If you are on version 11 or earlier
• Update. We no longer provide support for or add features and bug fixes to version 11.

❯ Which intents are privileged, which do I need?
GUILD_MEMBERS | guildMemberAdd, guildMemberRemove, guildMemberUpdate
GUILD_PRESENCES | presenceUpdate, knowledge about peoples activities and client status
• If your bot does not need this information to provide its functionality, please do not request it.

❯ How can I do things without these events?
• Try to design your commands so they do not require this information
• Fetch member data by ID as you need it <Guild>.members.fetch("id")
• You have GUILD_MEMBERS: consider fetching members periodically, for the initial operation on boot you can consider using the client option fetchAllMembers (note: this will heavily increase memory usage)

❯ A) Your bot is verified
• You need to reach out to discord support R3 in order for intents to be enabled
• Please include a use case sample as to why you need that intent into your request
• Read R1, it explains the whole procedure and requirements

❯ B) Your bot is not verified
• You can switch the toggles (attached image)
• You should still consider designing your commands to not require privileged intents where ever possible

❯ Symptoms you might be experiencing right now:
• member caches are empty (or only have very few entries)
• user cache is empty (or has only very few entries)
• fetching members times out
• all members appear to be offline
• login times out if you try to fetch all members on startup
• The client events "guildMemberAdd", "guildMemberRemove", "guildMemberUpdate" do not emit
Guild#memberCount returns count as of ready

❯ Resources
R1 Discords FAQ: https://dis.gd/gwupdate
R2 Discord Developer Portal: https://discord.com/developers/applications
R3 Discord Support: https://dis.gd/contact

As of _27/10/2020_ (warned since October 7, 2020), Discord has started enforcing intents and developers are required to enable them for receiving certain gateway events. Read the guide on intents.

Thank you @Extroonie ! I could not figure this out this morning, you're a life saver!

This happened to my discord server after having 1500+ members.

This happened to my discord server after having 1500+ members.

Well then since this already has a solution, please follow it.

As of 27/10/2020 (warned since October 7, 2020), Discord has started enforcing intents and developers are required to enable them for receiving certain gateway events. Read the guide on intents.

It took me several days to reach here. I wish I had found this long back. Thank you @Extroonie

Was this page helpful?
0 / 5 - 0 ratings