0

Thats' my "final" code that doesn't work at all and showing me

TypeError: list.members is not iterable.

Can anybody help me with this problem?

const list = bot.guilds.cache.get(guild_id); 
            for(member of list.members){
                console.log(member.user.username);
            }

Where bot is a Discord.Client()

1 Answer 1

1

You need to access the members cache in order to get the collection and loop through it.

const list = bot.guilds.cache.get(guild_id); 
for(member of list.members.cache){
    console.log(member.user.username);
}
3
  • 1
    It only returns 2 members out of 5 in a test server. Me and the Bot.
    – Beyondo
    Commented Nov 24, 2020 at 21:51
  • 1
    @Beyondo That's because you did not setup your Privileged Gateway Intents, you can change them in the Bot tab of your Application's page. In this case, you'd have to enable the Server Members Intent.
    – Syntle
    Commented Nov 24, 2020 at 23:36
  • 1
    Woow. You actually saved me! Because it got me so confused for a long while... thank you.
    – Beyondo
    Commented Nov 25, 2020 at 0:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.