I want to get all the users in my servers on ready of my discord bot so that I can add them to a database.
I have the discord privileged gateway intents all turned on. But I am only getting the id of a single user with the following code:
client.once('ready', () => {
client.guilds.cache.values().next().value.members.list().then((members) => {
members.each(member => {
console.log(member.id)
});
})
})
I am sure I have included all the intent that would be necessary while creating my client:
const client = new Client({ intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_BANS", "GUILD_EMOJIS_AND_STICKERS",
"GUILD_INTEGRATIONS", "GUILD_WEBHOOKS", "GUILD_INVITES", "GUILD_VOICE_STATES", "GUILD_PRESENCES", "GUILD_MESSAGES",
"GUILD_MESSAGE_REACTIONS", "GUILD_MESSAGE_TYPING"]} )
I dont know why it is giving id of only 1 member (owner) while the test server has 3 members including the bot.
CodePudding user response:
client.guilds.cache.get(guild_id).members.cache.map(member => member.id)