Making a bot in Discord.js, and i wanna see how many users the are in the servers that the bot is in(excepting the bots of the servers)
I’ve been trying for weeks but when i wanna get the value, it gives me something else..
Here’s my code:
var AllUsers = 0
client.on('ready', () => {
client.guilds.cache.forEach( guild => {
var memners = 0
mems = mems + guild.memberCount
var Bcount = 0
Bcount = Bcount + guild.members.cache.filter(member => !member.user.bot).size
var users = mems - Bcount
AllUsers = AllUsers + users
})
console.log(`the bot is ready and dealing with ${AllUsers} users`)
}
In this code i’m actually excepting the count of the bots from the memberCount itself, but my problem is that it just doesn’t work! the code guild.members.cache.filter(*member* => !member.user.bot).size
doesn’t work! it doesn’t give me an error..
It actually gives me this(i made some console.logs for that):
in my Bots server:
members: 5
Bcount: 1
users: 4
AllUsers: 4
---------
in Code server:
members: 4
Bcount: 1
users: 3
AllUsers: 7
---------
in Games server:
members: 3
Bcount: 1
users: 2
AllUsers: 9
---------
Its like the value of the Bcount is “1
” while it’s not!
I’ve tried the: guild.members.cache.filter(member => member.user.bot).size instead of: guild.members.cache.filter(member => !member.user.bot).size
and this time the value of the Bcount was “0
“.
It’s really ridiculous! cause all those three servers have 2 bots in it but it gave me 1 and 0!
Please if you know how to solve this problem help me.
thank you.