I want to retrieve all my users of all guilds where my bot is used at. What i need is a total(global) of these :
presence?.status == "offline")
presence?.status == "online")
presence?.status == "DND")
presence?.status == "bots")
well what i did is this and it returned 0 :
let userCount = message.client.users.cache.filter(member => member.presence?.status == "offline").size
console.log("total",userCount)
If i want to return everyone as a total(global) that works normal:
let userCount = message.client.users.cache.size;
console.log("total",userCount)
if i do this i get them but seperate,i need a total.
client.guilds.cache.forEach((guild) => {
const total = guild.members.cache.filter(member => member.presence?.status == "online").size
console.log(total)
}
any idea how to do this? i'm on v13
regards
Using forEach() might be a possible solution. We are going to use the increment operator (++). For example, something like this should work:
let userCount = 0;
client.guilds.cache.forEach((guild) => {
Array.from(guild.members.cache.filter(member => member.presence?.status === 'online').values()).forEach(() => userCount++);
});
console.log(userCount);
Hoped this helped!