Counting voice

Uncorrected counting voice channels members
4 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\OP10mo ago
I don't understand what the problem is, when participants enter the channel, it catches, and when they leave, it doesn't.
const update = async() => {
await console.log('Начало обновления банера.')
const newVoiceMembers = await guild.voiceStates.cache.size;
const newTotalMembers = await guild.memberCount;

if (voiceMembers !== newVoiceMembers) {
voiceMembers = newVoiceMembers;
await console.log('Новое количество участников в голосовых каналах получено.');
await console.log(`Теперь участников в голосовых каналах: ${voiceMembers}`);
}

if (totalMembers !== newTotalMembers) {
totalMembers = newTotalMembers;
await console.log('Новое общее количество участников получено.');
await console.log(`Теперь общее количество участников: ${totalMembers}`);
}
};

const combinedFunction = async () => {
newVoiceMembers = await guild.voiceStates.cache.size;
newTotalMembers = await guild.memberCount;

if (voiceMembers == newVoiceMembers && totalMembers == newTotalMembers) {
return console.log('Нет нужды в смене банеров.')
}

voiceMembers = newVoiceMembers;
totalMembers = newTotalMembers;

await update();
bannerUpdate();
};

setInterval(combinedFunction, 10 * 1000);
const update = async() => {
await console.log('Начало обновления банера.')
const newVoiceMembers = await guild.voiceStates.cache.size;
const newTotalMembers = await guild.memberCount;

if (voiceMembers !== newVoiceMembers) {
voiceMembers = newVoiceMembers;
await console.log('Новое количество участников в голосовых каналах получено.');
await console.log(`Теперь участников в голосовых каналах: ${voiceMembers}`);
}

if (totalMembers !== newTotalMembers) {
totalMembers = newTotalMembers;
await console.log('Новое общее количество участников получено.');
await console.log(`Теперь общее количество участников: ${totalMembers}`);
}
};

const combinedFunction = async () => {
newVoiceMembers = await guild.voiceStates.cache.size;
newTotalMembers = await guild.memberCount;

if (voiceMembers == newVoiceMembers && totalMembers == newTotalMembers) {
return console.log('Нет нужды в смене банеров.')
}

voiceMembers = newVoiceMembers;
totalMembers = newTotalMembers;

await update();
bannerUpdate();
};

setInterval(combinedFunction, 10 * 1000);
I'm not asking you to fix the code for me, I'm asking you to tell me what the problem might be.
Syjalo
Syjalo10mo ago
Voice states count isn't members in voice channels count. You need to filter voice states where channelId is present
/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\OP10mo ago
This will load the bot a lot, that's what I tried, as a result, everything is the same, the user cache only grows, and if you clean it manually, then all the participants who were in the voice ones are not taken into account when counting. Okay, there is promotion, but I don't really understand how to get the number of participants with the help of this event. I'm not talking about that, I'm talking about the fact that I need to get the numerical equivalent of all participants in voices I use a handler to load events from a separate file Sorry for my bad English Maybe I didn't understand something
client.on(Events.VoiceStateUpdate, (oldState, newState) => {
if (oldState.channelID === null && newState.channelID !== null) {
voiceMembers++;
console.log('Пользователь вошел в голосовой канал!');
} else if (oldState.channelID !== null && newState.channelID === null) {
voiceMembers--;
console.log('Пользователь вышел из голосового канала!');
}

console.log(`Текущее количество участников в голосовых каналах: ${voiceMembers}`);
});
client.on(Events.VoiceStateUpdate, (oldState, newState) => {
if (oldState.channelID === null && newState.channelID !== null) {
voiceMembers++;
console.log('Пользователь вошел в голосовой канал!');
} else if (oldState.channelID !== null && newState.channelID === null) {
voiceMembers--;
console.log('Пользователь вышел из голосового канала!');
}

console.log(`Текущее количество участников в голосовых каналах: ${voiceMembers}`);
});
But it doesn't work, it's not my thing, before that, of course, I somehow coped with God's help. :wolfy_derp: The very moment when the case or comma was lost @Qjuh Thank you very much for the explanation, I understood what I was doing wrong, I tried to read users in the loop every time, although it was easier to just count those who left and entered, while giving as the main number, the number of participants in voice channels, you really helped me figure it out. I'm sorry that I was so stupid, it's just that I myself speak Russian or Belarusian, and it's a couple of difficult to understand guides and documentation. Thank you again.
Want results from more Discord servers?
Add your server