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

290
Vistas
how to check if the member is joined to an specific voice channel DiscordJS

I want to check if the member is joined to the voice channel that the bot is joined. The whole code is working, I just want to add that line that I put in code comments. My code:

const { QueryType } = require('discord-player');
const { MessageEmbed } = require('discord.js');

module.exports = {
    name: 'play',
    aliases: ['p'],
    permissions: ['CONNECT'],
    description: 'Plays a music',
    voiceChannel: true,

    async execute(message, args, cmd, client, Discord, profileData) {
// if the member that used the comamnd is not joined to the voicechannel that the bot is playing music on it, return;
        const player = client.player
if (!args[0]) return message.channel.send({ content: `${message.author}, Write the name of the music you want to search. <:Cross:961558777667149874>` });

        const res = await client.player.search(args.join(' '), {
            requestedBy: message.member,
            searchEngine: QueryType.AUTO
        });

        if (!res || !res.tracks.length) return message.channel.send({ content: `${message.author}, No results found! <:Cross:961558777667149874>` });

        const queue = await client.player.createQueue(message.guild, {
            metadata: message.channel
        });

        try {
            if (!queue.connection) await queue.connect(message.member.voice.channel)
        } catch {
            await client.player.deleteQueue(message.guild.id);
            return message.channel.send({ content: `<:Cross:961558777667149874> ${message.author}, I can't join audio channel ` });
        }

if(client.config.opt.selfDeaf === false) {
let channel = message.member.voice.channel;
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
   channelId: channel.id,
   guildId: channel.guild.id,
   adapterCreator: channel.guild.voiceAdapterCreator,
   selfDeaf: false
});
}

        res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]);

        if (!queue.playing) await queue.play();
        

    },
};

I am not getting any errors. I am using node.js v16 and discord.js v13

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use this code to return if the member isn't in the same voice channel as you.

if(message.member.voice.channelId !== message.guild.me.voice.channelId) return;

Then it will return if they aren't in the same 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