Discord.js: Can not get all user IDs on a server.

Created on 19 Nov 2020  ·  5Comments  ·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

Can not get all user IDs on a server.

Include a reproducible code sample here, if possible:

let channels = client.guilds.cache;
console.log('channels', channels);

for (let [key, value] of channels) {
  console.log('value.memberCount', value.memberCount) // return 3
  console.log('value.members.cache.size', value.members.cache.size) // reutrn 1
  value.members.cache.forEach(data => {
    console.log('value.members.cache.forEach', data)
  }) // return bot info
  value.members.fetch()
  .then(console.log)
  .catch(console.error); // no data
}

Where are the others? 3 people in total.

but use

let channels = client.guilds.cache;
console.log('channels', channels);

for (let [key, value] of channels) {
  value.members
    .fetch({ user: '123456' })
    .then(console.log)
    .catch(console.error);
}

I can get the user

I want to get all user IDs on a server.

Further details:

  • discord.js version:12.4.1
  • Node.js version: 12.19.0
  • Operating system:win10
  • Priority this issue should have – please be realistic and elaborate if possible:

Relevant client options:

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

Most helpful comment

Yes, I have solved this problem, thank you very much, need to add code and set this

image

const client = new Discord.Client(
{fetchAllMembers: true}
);

fetchAllMembers options will use loooooog time

thank you very much @millette @advaith1

@netcell you can use the setting and the code

All 5 comments

I have the same problem. The only user in cache is the client user.
When I use await guild.members.fetch() the promise never resolve or reject, it just hang.

not a bug: #4961

不是错误:#4961

const client = new Discord.Client(
  {fetchAllMembers: true}
  );

How to solve this problem, this code does not work

Events for privileged intents are not sent if not enabled:

  • Discords FAQ on this change: https://dis.gd/gwupdate
  • your bot is verified? https://dis.gd/contact (and tell them which privileged intents you need and why)
  • your bot is __not__ verified? toggle the switches in https://discord.com/developers/applications (image)
  • you do __not__ need to provide intents in client options, discord sends all events if no intents are provided.
  • If you are on v11 and experience issues: update to v12, we no longer support v11.

Yes, I have solved this problem, thank you very much, need to add code and set this

image

const client = new Discord.Client(
{fetchAllMembers: true}
);

fetchAllMembers options will use loooooog time

thank you very much @millette @advaith1

@netcell you can use the setting and the code

Was this page helpful?
1 / 5 - 1 ratings