Search code examples
javascriptnode.jsdiscorddiscord.js

User in voice channel


I am trying to make a Discord music bot, but message.member.voice.channel always returns null. I have seen many other questions like that on stackoverflow, but none of them seem to help me. Here's the code:

     function play(message, args) {
        const VoiceChannel = message.member.voice.channel;
        console.log(VoiceChannel);
        if(!VoiceChannel) message.reply('You need to be in a voice channel');
        if(!args.length) message.reply('You need to specify song name');
    }
    /*............................................................................*/
if(command === 'play'){
    play(message, args);
}

(args.length works as it should, unlike VoiceChannel)


Solution

  • Assuming the current intents are GUILDS and GUILD_MESSAGES the problem must be coming from the missing GUILD_VOICE_STATES intent. Make sure to include it in the intents array and it should fix your problem.