Answer the question
In order to leave comments, you need to log in
How to count server members with discord.js bot?
I wrote a code that counts the participants on the discord server, as well as the number of people in the voice channels. However, the bot returns the value of the number of participants along with the bots. How to change the code so that the number of participants is without bots, and also add separate statistics by status - online, not active, do not disturb. Here is the code
robot.on('message', async (msg) => {//Number of server members
if (msg.partial) {
try {
await msg.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
return;
}
}
let voiceChannels = msg.guild.channels.cache.filter(c => c.type === 'voice');
let count = 0;
for (let [id, voiceChannel] of voiceChannels) count += voiceChannel.members.size;
robot.channels.fetch('813054508015288360').then(channel => {
channel.setName("Cats:"+ msg.guild.memberCount + ' ' + count)});
});
Answer the question
In order to leave comments, you need to log in
I hope you know where to enter)
and to distinguish bots from members simply where "members" subtract the number of bots, for example:
${members - 1}
async function timemembercount() {
let members = bot.guilds.cache.get("GuildID").memberCount
bot.channels.cache.get("ChannelID").setName(`Котиков: ${members}`);
}
var interval = setInterval(function () { timemembercount(); }, 20000 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question