0

This is the code

 module.exports = async (client) => {
        let myGuild = client.guilds.cache.get(guild.id)

            setInterval(() =>{

            var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size
    
            let memberCountChannel = myGuild.channels.cache.get(channel.id);
            console.log(onlineCount.name);
            memberCountChannel.setName(onlineCount + 'people online')
            .then(result => console.log(result))
            .catch (error => console.log(error));
        }, 5000)
    }

And this is the part that counts the members

var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size

What the terminal shows

undefined
undefined
undefined
undefined
undefined
SlendyX
  • 3
  • 1

2 Answers2

1

filter method returns an array, and arrays do not have size property. Use length property and it will be ok.

Please check this answer also: https://stackoverflow.com/a/14202745/10500500

var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").length
0

Since you are restarting the bot the data is not cached, you firstly need to fetch the members with <Guild>.members.fetch method. Else it means you didn't activate intents, refer here.

Example for your case:

await myGuild.members.fetch();
var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size;
Leau
  • 1,072
  • 5
  • 19