Ive been trying to get this code for a music bot to work, i have all the dependencies but i think its because the video i watched is from around 8 months ago and alot of the code is defunct.
Currently i get an error TypeError: Cannot read property 'join' of undefined. If someone can help me fix the problem and get it to work that would be amazing.
bot.on('message', message => {
if (!message.content.startsWith(PREFIX)) return;
let args = message.content.slice(PREFIX.length).split(" ");
switch(args[0]){
case 'play':
function play(connection, message){
var server = servers[message.guild.id];
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
})
}
if(!args[1]){
message.channel.send("you need to provide a link!");
return;
}
if(!message.member.voice.channel.join){
message.channel.send("You must be in a voice channel to play music!");
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voiceConnection)message.member.voiceChannel.join().then(function(connection){
play(connection, message);
})
break;
}
})