Harry Allen
Harry Allen

Reputation: 473

Discord js: How would i get an array of all members in a server?

I need to get a list of all the members in a server. I tried

client.guilds.cache.get(message.guild.id).members.cache.array()

but for some reason, it only returned 2 users: me, and the bot, despite the fact that there are more than 2 members of my server. Is this the correct way of getting the users, and should this code work?

Upvotes: 0

Views: 258

Answers (1)

Akio
Akio

Reputation: 723

Add this when declaring client

const client = new Discord.Client({ ws: { intents: [ 'GUILD_MEMBERS'] }});

Then turn on gateway intents in Discord Developer Portal

Then look for gateway intents

It should look like this after turning on intents

Note: Once you hit 100 servers it'll need whitelisting and some time to be approved / verified by Discord(Mine took about 3 months)

Upvotes: 1

Related Questions