Is there a way to check how many members are in a voice channel or if it's empty in discord.js (V. 13.8.1)?
I have already tried this
async function usercount(voiceState){
let users = await(voiceState.channel.fetch.memberCount);
console.log(users)
}
CodePudding user response:
VoiceChannel#members
is a collection of the members in a voice-based channel. Collection's have a size
property, so something like this should work:
function usercount(voiceState) {
let { members } = voiceState.channel;
console.log(members);
return members.size;
}
CodePudding user response:
Can use the VoiceChannel.members.size
to get how many members are in the channel.
Here's an example:
const GuildMember = new Discord.GuildMember(); // This shall be the command author.
if (GuildMember.voice.channel)
{
console.log(GuildMember.voice.channel.members.size);
};