Reputation: 429
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