Closed KidOfEpicness closed 6 years ago
When I paired this with Discord.js, if I already had something in the queue, it would say Cannot read property 0 of undefined when trying to read the first item in the array returned by this module.
Cannot read property 0 of undefined
Code: if(command === "play") { const queue = getQueue(message.guild.id); const qq = getTQueue(message.guild.id) if(!message.member.voiceChannel) return message.reply('please join a voice channel first.');
message.member.voiceChannel.join().then(connection => { var YouTubeSearch = require('youtube-search');
var opts = { maxResults: 1, key: "AIzaSyD7plXhX_-V8AMMKavnDs6HNbPWIiZgF2U" }; YouTubeSearch(args.slice(1).join(" "), opts, (err, results) => { var video = results[0]; if(err) return message.channel.send(`I encountered an error when trying to find ${args.slice(1).join(" ")}\n\`\`\`xl\n${err}\`\`\``) qq.push(`${video.title} by ${video.channelTitle}`); message.channel.send(`Queued \`${video.title}\` By \`${video.channelTitle}\` `); queue.push(video.link); if(!message.guild.voiceConnection.player.dispatcher) var dispatcher = connection.playStream(ytdl(queue[0], { filter: "audioonly", volume: 0.2 })); connection.on("end", () => { if(queue[1]) { qq.shift(); queue.shift(); var dispatcher = connection.playStream(ytdl(queue[0], { filter: "audioonly", volume: 0.2 })); } }); dispatcher.on("end", () => { qq.shift(); queue.shift(); if(queue[0]) var dispatcher = connection.playStream(ytdl(queue[0], { filter: "audioonly", volume: 0.2 })); if(!queue[0]) message.member.voiceChannel.leave(); if(!queue[0]) message.channel.send(`Queue completed.`) })
}); }); };
Please see the README.md on how this module is used.
README.md
When I paired this with Discord.js, if I already had something in the queue, it would say
Cannot read property 0 of undefined
when trying to read the first item in the array returned by this module.Code: if(command === "play") { const queue = getQueue(message.guild.id); const qq = getTQueue(message.guild.id) if(!message.member.voiceChannel) return message.reply('please join a voice channel first.');
message.member.voiceChannel.join().then(connection => { var YouTubeSearch = require('youtube-search');
}); }); };