Reputation: 11
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' ]
Upvotes: 1
Views: 1345
Reputation: 1196
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:
Upvotes: 1
Reputation: 23161
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 GuildMember
s:
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.
Upvotes: 1