Home > Blockchain >  Get all users in voice channels with discord.js
Get all users in voice channels with discord.js

Time:05-27

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.

CodePudding user response:

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.

  • Related