Im not good with javascript but i have been trying to get count number of users in all voice channels. For example: if 2 users in ‘voice channel 1’ and 1 user in ‘voice channel 2’ I want to print number 3 in console which is all users in voice channels.
var Count; for(Count in bot.users.array()){ var User = bot.users.array()[Count]; console.log(User.username); }
This code print all members(online/offline) name in console, But i don’t know how to get number of only users in voice channels.
Advertisement
Answer
You can filter (Collection.filter()
) all the channels in the guild (Guild.channels
) to retrieve a Collection of only voice channels. Then, you can iterate through each channel and add the number of members connected to it to the count.
// Assuming 'newMember' is the second parameter of the event. const voiceChannels = newMember.guild.channels.filter(c => c.type === 'voice'); let count = 0; for (const [id, voiceChannel] of voiceChannels) count += voiceChannel.members.size; console.log(count);