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

119
Visualizações
Issues using the voice guide

I am trying to make my bot leave the voice channel, using the code from discordjs guide (discord version dev 14.0.0 )

when I try to acces the created connection, it errors: ReferenceError: myVoiceChannel is not defined.

my code in the leave command:

const Command = require('../Structures/Command.js');
const { getVoiceConnection } = require("@discordjs/voice");
const connection = getVoiceConnection(myVoiceChannel.guild.id);



module.exports = new Command({
    name: "lvc",
    description: "leaves voice",
    permission: "CONNECT",

    async run(message, args, client) {
        connection.destroy();        
    }
})

my code in the join command:

const Command = require('../Structures/Command.js');
const { VoiceConnectionStatus, AudioPlayerStatus, AudioPlayer, joinVoiceChannel } = require('@discordjs/voice');


module.exports = new Command({
    name: "join",
    description: "joins voice",
    permission: "CONNECT",

    async run(message, args, client) {
        const connection = joinVoiceChannel({
            channelId: "904277856773869583",
            guildId: message.guild.id,
            adapterCreator: message.guild.voiceAdapterCreator
        })
    }, 

})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your first code you've added the code

const connection = getVoiceConnection(myVoiceChannel.guild.id);

Nowhere in your code you've defined myVoiceChannel. This is the reason why this error is being thrown. You could use this example instead:

const Command = require('../Structures/Command.js');
const { getVoiceConnection } = require("@discordjs/voice");


module.exports = new Command({
    name: "lvc",
    description: "leaves voice",
    permission: "CONNECT",

    async run(message, args, client) {
        const connection = getVoiceConnection(message.guild.id);
        if(connection) connection.destroy();
        else return message.channel.send({ content: `I am not connected to a voice channel` });
    }
})
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