Reputation: 11
How do I filter out the bots in this code so that only users are displayed?
const Discord = require('discord.js')
const token = require('./token.json').token
const client = new Discord.Client();
setInterval(async () => {
let membersCount = client.guilds.cache.map(guild => guild.memberCount).reduce((a, b) => a + b, 0)
await client.user.setPresence({
activities: [{
name: `mit ${membersCount} usern`,
type: ActivityType.Playing
}],
status: "online"
})
}, 1000 * 60 * 10);
client.login(token)
Upvotes: 1
Views: 82
Reputation: 2370
You can use the client.users
property then using the Array.prototype.filter()
function.
Example:
client.users.cache.filter(user => !user.bot).size
Full Example:
const Discord = require('discord.js')
const token = require('./token.json').token
const client = new Discord.Client();
setInterval(async () => {
let membersCount = client.users.cache.filter(user => !user.bot).size;
await client.user.setPresence({
activities: [{
name: `mit ${membersCount} usern`,
type: ActivityType.Playing
}],
status: "online"
})
}, 1000 * 60 * 10);
client.login(token)
Upvotes: 2