Get all users in voice channels with discord.js

Issue

I’m trying to get the list of users in voice channel :

client.on("messageCreate", message => {
if (message.author.bot) return false;

if (message.content.toLowerCase() == "test") { console.log( message.guild.members.cache.filter(member => member.presence == "online"));

};

I’m note sure if guild.members.cache is the right way.

I’m using discord.js 13.7.0

Any idea ?

The purpose, after I get the list users, the bot will split them randomly into two channel.

Solution

message.guild.members.cache.filter(member => member.voice.channel)

VoiceState#channel is the voice (or stage) channel that a user is connected to. If they are not connected to a VC, this property is null.

Answered By – cherryblossom

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.