Reputation: 11
Im using discord.js for bot making, and i keep getting this error when im trying to make a music bot?? I dont know how to define member. it also wont even join the channel or obviously play music, the only thing that works is the function that tells theres a link needed for the bot to continue
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case 'play':
function play(connection, message){
var server = severs[message.guild.id];
server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audio"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}
else {
connection.disconnect();
}
});
}
if(!args[1]){
message.channel.send("Link needed!");
return;
}
if(!message.member.voiceChannel){
message.channel.send("You must be in a channel!");
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
};
var server = servers[message.guild.id];
server.queue.push(args[1]);
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voiceConnection) member.voiceChannel.join().then(function(connection){
play(connection, message);
});
break;
case "skip" :
var server = servers[message.guild.id];
if (server.dispatcher) server.dispatcher.end();
break;
case "stop":
var server = server[message.guild.id];
if(message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
break;
}
Upvotes: 1
Views: 662
Reputation: 11
I don't know about much on scripting or discord.js, but
you could use connection.play()
instead of connection.playStream()
Upvotes: 1
Reputation: 5355
Where did the error occur? But based on:
if(!message.member.voiceChannel){
message.channel.send("You must be in a channel!");
return;
}
Did you mean
message.member.voiceChannel.join().then(
instead of
member.voiceChannel.join().then(
Upvotes: 1