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

260
Vistas
Connection.Destroy() Leave channel voice discordjs v13

This is my code to "leave a voice channel, but as you can see it is not functional, when I use the command, if it is not in a voice channel it sends me the message" I am not in a voice channel.

I want to make it get out of the voice channel without using the const connection = since this is the reason why the if connect and disconnect is bugged.

I am new and I am experimenting with this, I understand the logic of the programming but in this case I do not know what to do

if(message.member.voice.channel)
        {
            const connection = joinVoiceChannel({
                channelId: message.member.voice.channel.id,
                guildId: message.guild.id,
                adapterCreator: message.guild.voiceAdapterCreator,
                });
            message.channel.send("Disconected!");
        }
        message.channel.send("i am not in a channel voice");
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here's how it works

client.on('messageCreate', async (message) => {

    if (message.content.toLocaleLowerCase() === prefix + 'join') { //Here's how to join a voice channel 

        if (!message.member.voice.channel) return message.channel.send('You need to be a voice channel to execute this command!')
        if(!message.member.voice.channel.joinable) return message.channel.send('I need permission to join your voice channel!')

        const connection = joinVoiceChannel({
            channelId: message.member.voice.channel.id,
            guildId: message.member.guild.id,
            adapterCreator: message.channel.guild.voiceAdapterCreator
        })

        console.log('Connected to voice!');
    }

    if (message.content.toLocaleLowerCase() === prefix + 'leave') { //Here's how to leave from voice channel
        const connection = getVoiceConnection(message.guild.id)

        if(!connection) return message.channel.send("I'm not in a voice channel!")

        connection.destroy()

        console.log('Disconnected from voice!');
    }
});

Here's full code

const { Client, Intents } = require('discord.js')
const { joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice')

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_VOICE_STATES /// <= Don't miss this :)
    ]
});

var prefix = '!'

client.on('ready', async () => {
    console.log('Client is Ready...');
});

client.on('messageCreate', async (message) => {

    if (message.content.toLocaleLowerCase() === prefix + 'join') { //Here's how to join a voice channel 

        if (!message.member.voice.channel) return message.channel.send('You need to be a voice channel to execute this command!')
        if(!message.member.voice.channel.joinable) return message.channel.send('I need permission to join your voice channel!')

        const connection = joinVoiceChannel({
            channelId: message.member.voice.channel.id,
            guildId: message.member.guild.id,
            adapterCreator: message.channel.guild.voiceAdapterCreator
        })

        console.log('Connected to voice!');
    }

    if (message.content.toLocaleLowerCase() === prefix + 'leave') { //Here's how to leave from voice channel
        const connection = getVoiceConnection(message.guild.id)

        if(!connection) return message.channel.send("I'm not in a voice channel!")

        connection.destroy()

        console.log('Disconnected from voice!');
    }
});

client.login('BOT TOKEN HERE!');
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