G
G
getaxe2021-02-04 05:53:19
Node.js
getaxe, 2021-02-04 05:53:19

How to display people in voice channels discord js?

Hello, I am writing a people counter on the server and in Voice channels.
I figured out memberCount by checking the box in the bot's personal account. (SERVER MEMBERS INTENT)
But it doesn't work with online voice channels. It remembers the number, and even after the person exits it is not updated, thus this indicator only grows until the bot is restarted. (I also tried to check the PRESENCE INTENT box on the developer portal) Please help, below is the code.
ps for this I have a separate js file.

module.exports = (client) => {
  async function members() {
    const guild = await client.guilds.fetch("id сервера/гильдии");
    let members = guild.memberCount.toLocaleString();
    client.channels.cache.get("78677696201306****").setName(`Участники: ${members}`); 
  }

  async function online() {
    const guild = await client.guilds.fetch("id сервера/гильдии");
    let voiceonline = guild.voiceStates.cache.size.toLocaleString();
    console.log(voiceonline);
    client.channels.cache.get("80671070358654****").setName(`Voice: ${voiceonline}`);  
  }

  var interval = setInterval(function () {members(), online() }, 600000  );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ettychel, 2021-02-17
@getaxe

let voiceonline = guild.voiceStates.cache.filter(e => e.channelID).size;

.toLocaleString() - This is optional, because JS itself will convert to a string during your further operation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question