2019-10-10 13:43:04 +00:00
|
|
|
module.exports = async function (guild, song, client, message, seek) {
|
2019-09-15 06:18:33 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const ytdl = require('ytdl-core');
|
|
|
|
const serverQueue = client.queue.get(guild.id);
|
|
|
|
if (!song) {
|
|
|
|
serverQueue.voiceChannel.leave();
|
|
|
|
client.queue.delete(guild.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const dispatcher = serverQueue.connection
|
2019-10-11 11:30:10 +00:00
|
|
|
.playStream(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 })
|
2019-09-15 06:18:33 +00:00
|
|
|
.on("end", reason => {
|
2019-10-10 13:43:04 +00:00
|
|
|
if (reason === "Stream is not generating quickly enough.") {
|
2019-09-15 06:18:33 +00:00
|
|
|
console.log("Song ended");
|
2019-10-10 13:43:04 +00:00
|
|
|
} else if (reason === "seek") {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
console.log(reason);
|
|
|
|
}
|
2019-10-12 09:49:24 +00:00
|
|
|
if (serverQueue.looping) {
|
|
|
|
serverQueue.songs.push(serverQueue.songs[0]);
|
2019-10-12 08:14:12 +00:00
|
|
|
}
|
2019-10-12 09:49:24 +00:00
|
|
|
serverQueue.songs.shift();
|
2019-10-10 13:43:04 +00:00
|
|
|
client.funcs.play(guild, serverQueue.songs[0], client, message);
|
2019-09-15 06:18:33 +00:00
|
|
|
});
|
2019-10-10 13:43:04 +00:00
|
|
|
dispatcher.setVolume(serverQueue.volume / 10);
|
2019-09-15 06:18:33 +00:00
|
|
|
dispatcher.on("error", error => console.error(error));
|
2019-10-12 10:34:38 +00:00
|
|
|
//let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
|
|
|
|
//let songtime = (data.length_seconds * 1000).toFixed(0);
|
2019-10-12 08:13:55 +00:00
|
|
|
const embed = new Discord.RichEmbed()
|
|
|
|
.setTitle(`:musical_note: Start playing: **${song.title}**`)
|
2019-10-12 10:34:38 +00:00
|
|
|
//.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
|
2019-10-12 08:13:55 +00:00
|
|
|
.setColor("#b50002")
|
2019-10-12 10:38:12 +00:00
|
|
|
serverQueue.textChannel.send(embed);
|
2019-10-10 13:43:04 +00:00
|
|
|
}
|