Reputation: 308
So I'm very new to node.js/discord.js, thats why I want to ask you something. On my first Bot I want to mak a global User Count, witch shout look like in the Picture below.. I tried the following code, but with this, the usercount is changing evry second.
client.on('message', message => {
if (message.content === 'm!info') {
const embed = new Discord.RichEmbed()
.setColor('#0099ff')
.setTitle('Informations')
.addField('Version','V 0.3')
.addField('Dev.','@myname')
.addField('Ping', `Der Bot hat einen Ping von **${client.ping} ms**!`)
.addField('Server', `${client.guilds.size}`)
.addField('User', `${client.users.size} (Verbugt)`)
.setTimestamp()
message.channel.send(embed);
}
});
Would be great If someone can help me. Thats the unrealistic Usernumber
Upvotes: 0
Views: 352
Reputation: 3005
client.users
are the cached users. You can do it this way:
let userCount = client.guilds.map((g) => g.memberCount).reduce((p, c) => p + c);
console.log(userCount); // 3241 for example.
The userCount won't change until a member joins or left a server. The disadvantage is that if a member is present on several servers, he will be counted twice. Otherwise, you are obliged to use client.users.size
...
Upvotes: 1