I made a member counting system for my server but it counts every member that is joined. I want to filter the counter to just count the humans/users
My code:
JavaScript
x
9
1
module.exports = async (message, args, cmd, client, Discord, profileData) =>{
2
const guild = client.guilds.cache.get('847071265100791849');
3
setInterval(() =>{
4
const memberCount = guild.memberCount;
5
const channel = guild.channels.cache.get('863783336860975114');
6
channel.setName(`Users: ${memberCount.toLocaleString()}`);
7
}, 60000);
8
}
9
I am using discord.js v13 and node.js v16
Advertisement
Answer
You can just filter through all the members in a server and remove all the members which are bots by checking the member.user.bot
property. You can then update your code to:
JavaScript
1
9
1
const guild = client.guilds.cache.get('847071265100791849');
2
setInterval(() => {
3
let humanMembers = guild.members.cache.filter(
4
(user) => !user.user.bot // This checks if the the user is a bot
5
);
6
const channel = guild.channels.cache.get('863783336860975114');
7
channel.setName(`Users: ${humanMembers.size.toString()}`);
8
}, 60000);
9