Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!