Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
Disconnect a user from VC with a userID discord.js

I am having a tough time understanding the discord.js documentation. I am looking to have my bot disconnect a user based on their userID.

My code would ideally look something like this:

function disconnectUser(userID){
   userID.disconnect();
   return;
}

The code I have tried is varitions of:

function disconnectUser(userID){
   userID.VoiceState.disconnect();
   return;
}

And I get the error:

TypeError: Cannot read properties of undefined (reading 'disconnect')

Any help would be greatly appreciated :)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Discord.js v13

You simply need to fetch the member and the call the voiceState#disconnect() method on them like so:

async function disconnect(userID){
let user = await client.users.fetch(userID)
user.voice.disconnect();
}

For calling it you simply need to pass a snowflake ( user ID) as the function parameter like so:

disconnect(1234567890123456);

Discord.js v12

The voiceState#disconnect() method was called voiceState#kick() in v12 therefore you'd have to make the suitable changes if on v12.

Like so:

async function disconnect(userID){
let user = await client.users.fetch(userID)
user.voice.kick();
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Voice is not an attribute of "users", it is only a member of "guild.members". "guild.members" is created when a user joins a VC and is accessed via a message or an interaction. In my case using slash commands I got the guild by passing in the interaction to the disconnectUser() function. The working disconnect function works as below:

async function disconnectUser(userID, interaction){
    let user = await interaction.guild.members.fetch(userID);
    user.voice.disconnect();
}

Where interaction is essentially the same as message.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda