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

124
Vistas
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 Respuestas
Responde la pregunta

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 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