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;
}
})
The message.member.voiceChannel.join()
might need to be changed to message.member.voice.channel.join()
as of Discord v12
Looks like the problem is coming from here:
if(!message.member.voice.channel.join){ message.channel.send("You must be in a voice channel to play music!"); return; }
You'll need to remove the.join part, because no such thing exists in Discord.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.