0

I have been trying different ways to retrieve the current list of members in a specific channel (e.g. 'networking'). But I am only get one, the actual bot user inside the channel, but nothing else.

This is the latest version of the code I am trying.

client.channels.cache.filter((c) => c.name === 'networking').forEach(channel => {
    channel.fetch().then((channel) => {
        console.log(channel.name);
        for (let [snowflake, guildMember] of channel.members) {
            console.log(`${guildMember.displayName} (${guildMember.id})`);
        }
    });
});

It's probably something to do with caching but I'm just not able to find the right sequence. Any help would be appreciated.

Timus
  • 10,974
  • 5
  • 14
  • 28
  • I've also tried to assign a role to certain users and then retrieve all users in that role. That would also work for me,but same issue. I just don't get any. – rauldemarras Dec 23 '20 at 10:47
  • 1
    Do you have all of your [intents](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) turned on? – Tyler2P Dec 23 '20 at 11:09

1 Answers1

0

Thank you Tyler2P for the answer. You were absolutely right. Membership intents were disabled by default. I have lost so much time on this :) Thanks a million.

For everyone who gets to this question. Solution is so simple as enabling the "Server Members Intent".

Bot configuration in Discord Application page