Here the problem: I want to create a discord bot that alert me when someone join a channel. Code works, and display in console the number of users, but not update the counter each time. I have to restart it to have the update number. How to reset the counter and have the updated one? Thanks
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
client.once('ready', () => {
console.log(`Bot connected ${client.user.tag}!`);
});
setInterval(() => {
const voiceChannel = client.channels.cache.get('MY VOCAL CHANNEL ID');
console.log(`Number of people: ${voiceChannel.members.size}`);
if (voiceChannel.members.size > 0) {
console.log('Someone is here');
} else {
console.log('No one is here');
}
}, 1000);
;
client.login('MY BOT TOKEN');
I tried to clear cache, to set voiceChannel.members.size = 0 every end of cycle. I want the updated number of members every cycle.
you need use a
voiceStateUpdatesomething like blow