Get all users from all guilds [Discord.js]

Viewed 826

someone knows maybe what's wrong here because I'm making a system that I need to get all users from all guilds. I did something like you can see below, but it doesn't work. The problem with this is that it only downloads users from the guild on which the command was executed, not all guilds. If anyone can help, please.

const Guilds = client.guilds.cache.map(guild => guild.id)

console.log(Guilds)

for(const g of Guilds){
  msg.guild.members.cache.forEach(member => {
    if(!member.user.bot){

in the line console.log(Guilds) I get all guilds id

1 Answers

You're only getting the guild IDs because of the .map(guild => guild.id), instead you should loop trough the guilds and not trough the IDs like so:

let allUsers = []

client.guilds.cache.forEach(guild => {
  guild.members.cache.forEach(member => {
    if(member.user.bot) return
    allUsers.push(member)
  })
})
Related