Nathn
Nathn

Reputation: 429

Music Discord.js bot does not detect voice channel

I am currently making a music Discord Bot. My problem is at the fist lines of the command : even when the user is in a voice channel, voiceChannel is marked as undefined and the bot return "You have to be in a voice channel to use this command"

client.on("message", async message => {
  if(message.author.bot) return;
  const serverQueue = queue.get(message.guild.id);
  if(message.content.indexOf(PREFIX) !== 0) return;
  const args = message.content.slice(PREFIX.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
     if (command === "play" || command === "p") {
        const args = message.content.split(" ");
        const searchString = args.slice(1).join(" ");
        const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
        const serverQueue = queue.get(message.guild.id);
        const voiceChannel = message.member.voiceChannel;
        if (!voiceChannel) return message.channel.send("You have to be in a voice channel to use this command");
     }
});

Upvotes: 1

Views: 1020

Answers (1)

mmoomocow
mmoomocow

Reputation: 1227

have a look here

message.member.voiceChannel;

doesn't exist in discord.js version 12 and up

you need to use

message.member.voice.channel.

Upvotes: 1

Related Questions