discord.js v12 how to set owner commands
// First we use guild.members.fetch to make sure all members are cached.guild.members.fetch().then(fetchedMembers => { const totalOnline = fetchedMembers.filter(member => member.presence.status === 'online'); // We now have a collection with all online member objects in the totalOnline variable .channel.send(`There are currently ${totalOnline.size} members online in this guild!`); });
Here is what the above code is Doing:
1. We use guild.members.fetch to make sure all members are cached
2. We filter the fetched members to only keep the ones that are online
3. We send a message to the channel with the amount of online members