I have created this loop function to get every voice user every minute, but it does not work like I thought.
I get every Minute the same result. If I leve the voice Channel it will still show me my username in the console in the next call. It does not update the result.
function loop(){
setTimeout(loop, 60000)
client.guilds.cache.forEach(guild => {
console.log(`Voice users in ${guild.name}:`)
guild.voiceStates.cache.forEach(voiceState => {
if(voiceState.channel){
console.log(voiceState.member.displayName);
}
});
});
}
Make sure you have GUILD_VOICE_STATES
in your client's intents. Otherwise the client is not receiving VOICE_STATE_UPDATE
event.
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES"] });
For a complete list of intents and what they do see here.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments