Reputation: 19
Hey i'm trying to test a music bot with node.js and discord.js. I've put it in 2 servers, in the first one it works fine, in the second one it gives me cannot read property 'queue' of undefined and i don't know why.
const Discord = require("discord.js");
const config = require("./config.json");
const ytdl = require("ytdl-core");
const client = new Discord.Client();
const prefix = "..";
var servers = {};
client.on("message", message => {
let args = message.content.substring(prefix.length).split(" ");
function isValidURL(string) {
var res = string.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
return (res !== null)
};
switch(args[0]){
case "play":
function play(connection, message){
var serv = servers[message.guild.id];
serv.dispatcher = connection.play(ytdl(serv.queue[0], {filter: "audioonly"}));
serv.queue.shift();
serv.dispatcher.on("end", function(){
if(serv.queue[0]){
play(connection, message);
}else{
connection.disconnect();
}
});
}
if(!args[1]){
message.channel.send(message.author.toString() + " Devi mettere un link dopo il comando.");
return;
}else if(isValidURL(args[1]) == false){
message.channel.send(message.author.toString() + " Link non valido.");
return;
}else if(!message.member.voice.channel){
message.channel.send(message.author.toString() + " Devi essere in un canale vocale.");
return;
}else if(!servers[message.guild.id]) servers[message.channel.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.member.voice.connection) message.member.voice.channel.join().then(function(connection){
play(connection, message);
});
break;
}
});
client.login(config.BOT_TOKEN);
It might be something with servers permissions but they are the same. So i don't know, any idea?
Upvotes: 0
Views: 1015
Reputation: 21
The discord.js library may be updated to a new master version which the bot is not compatible with. Try using the version of discord.js which is used in the original source.
Upvotes: 2