I have this bot project, so basically the bot will show you how much server they in, and show you how much member that on that server you currently in, is there a way to fix this since it always show 1 users (which is me probably) meanwhile there's like 400 people in the server I'm in.
Here's my code:
const { MessageEmbed } = require("discord.js")
module.exports = async bot => {
console.log(`${bot.user.username} is now online!`)
var activities = [ `${bot.guilds.cache.size} servers`, `${bot.users.cache.forEach(guild)} users!` ], i = 0;
setInterval(() => bot.user.setActivity(`${PREFIX}help | ${activities[i++ % activities.length]}`, { type: "WATCHING" }),5000)
};
You could try using <Guild>.memberCount. The problem is that your code currently only grabs the cached users, which apparently is only one.
Edit: Here as requested a code example:
const { MessageEmbed } = require('discord.js');
module.exports = async bot => {
console.log(`${bot.user.username} is now online!`);
let counter = 0;
bot.guilds.cache.forEach(guild => {
counter += guild.memberCount;
});
const activities = [`${bot.guilds.cache.size} servers`, `${counter} users!` ], i = 0;
setInterval(() => bot.user.setActivity(`${PREFIX}help | ${activities[i++ % activities.length]}`, { type: 'WATCHING' }),120_000);
}
I did some more small changes... in general, don't use var, use either let or const. Also, you shouldn't be changing your status every 5 seconds since that's considered API spam. I changed your interval to 5 minutes instead which is more reasonable (but still a small number, if it doesn't matter too much for you I'd even set it to 10 minutes).