1

When I’m trying to get the member list from my discord server, djsv12 returns me a list, but it has only 1 entry.

In fact, there should be 23 entries instead because that's the amount of members on my server.

I don't understand what's wrong. You can find my code below:

const Guild = client.guilds.cache.first(); // My one server

const Members = Guild.members.cache.map(member => member.id);

console.log(Members);

Console:

[ '578565698461106204' ]
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
Chatsky
  • 11
  • 3

2 Answers2

1

Maybe it's because only one member is cached. Try to fetch all the members first.

members.fetch() fetches members from Discord, even if they're offline and returns promise that resolves to a collection of GuildMembers:

const guild = client.guilds.cache.first(); // My one server
const members = await guild.members.fetch();
const memberIDs = members.map((member) => member.id);

console.log(memberIDs);

PS: As I'm using the await keyword, make sure that you're in an async function.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
1

I believe you're encountering the same problem as mentioned in this question.

Since Discord has been implementing privileged intents, that means that you have to grant your bot permission access to certain data. This privilege is turned off by default.

To turn it on, simply go to the Discord Developer Portal. Then select your Application, then go to the Bot section on the left side and scroll down. You should see the two options "Presence Intent" and "Server Members Intent".


Resources:

  1. None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?
  2. Discord.js Guide - Gateway Intents
PerplexingParadox
  • 1,196
  • 1
  • 7
  • 26