Checking if a DiscordJS member has joined a particular voice channel

My code doesn’t seem to be working properly. Although it should play music when the bot joins the voice channel, it is not doing so. I am utilizing node.js v16 and discord.js v13. To fix this issue, you can implement the following code to check if the member is in the same voice channel as you before playing the music.


I need to verify whether the bot is connected to
voice channel
and if the member is also connected to the same channel. The code is functional, I only need to include the line mentioned in the comments section. Here’s my current 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{ content: `${}, Write the name of the music you want to search. <:Cross:961558777667149874>` });
        const res = await' '), {
            requestedBy: message.member,
            searchEngine: QueryType.AUTO
        if (!res || !res.tracks.length) return{ content: `${}, No results found! <:Cross:961558777667149874>` });
        const queue = await client.player.createQueue(message.guild, {
        try {
            if (!queue.connection) await queue.connect(
        } catch {
            await client.player.deleteQueue(;
            return{ content: `<:Cross:961558777667149874> ${}, I can't join audio channel ` });
if(client.config.opt.selfDeaf === false) {
let channel =;
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
   adapterCreator: channel.guild.voiceAdapterCreator,
   selfDeaf: false
        res.playlist ? queue.addTracks(res.tracks) : queue.addTrack(res.tracks[0]);
        if (!queue.playing) await;

No errors are occurring while utilizing node.js v16 and


This code can be utilized to check if the member is not present in the identical voice channel as you.

if(message.member.voice.channelId !== return;

It will come back if they are not present in the identical channel.

Frequently Asked Questions