Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
Discord.js | How to get members currently connected to a Voice Channel?

I'm trying to get the members who are currently connected to a specific voice channel. With some properties I could get them, but the problem I found was that the members who are listed aren't the ones who are currently connected but the ones who had been connected to the voice channel when the bot started running.

This is my code (it's shortened but is copied):

const {Client, Intents} = require('discord.js')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MEMBERS] })
client.on('messageCreate', messagesHandler)

function messagesHandler (msg) {
  if (msg.author.bot) return false;
  console.log(`Msg received: ${msg.content}`)

  if (msg.content.startsWith('/')) {
    const msgArr = msg.content.split(' ')

    switch (msgArr[0]) {
      case '/list':
        listCommand(msg, msgArr)
        break
    }
  }
}

async function listCommand (msg, msgArr) {
  if(!msgArr[1]) {
    const voiceChannel = await getChannel(msg, 'Voice1', true).fetch()
    if (!voiceChannel) {
      msg.channel.send('ERROR: Voice1 channel not found')
    } else {
      await getCurrentChannelMembers(msg, voiceChannel)
    }
  }
}

function getChannel(msg, channel, voiceChannel = false) {
  return msg.guild.channels.cache.find(c => c.name === channel && (!voiceChannel || c.isVoice()))
}

async function getCurrentChannelMembers (msg, channel) {
  const fetchedChannel = await channel.fetch(true)
  const members = fetchedChannel.members
  console.log('Members: ', members)
}

Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your bot needs GUILD_VOICE_STATES intent

const client = new Client({ 
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES, 
    Intents.FLAGS.GUILD_PRESENCES,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_VOICE_STATES
  ] 
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda