2020-02-05 20:02:53 +00:00
|
|
|
module.exports = async function (guild, song, client, seek, play) {
|
|
|
|
const Discord = require('discord.js');
|
|
|
|
const ytdl = require('ytdl-core');
|
|
|
|
const getThumb = require('video-thumbnail-url');
|
|
|
|
|
|
|
|
const serverQueue = client.queue.get(guild.id);
|
|
|
|
if (!song) {
|
|
|
|
console.log('No song')
|
|
|
|
serverQueue.voiceChannel.leave();
|
|
|
|
client.queue.delete(guild.id);
|
|
|
|
return;
|
|
|
|
}
|
2020-02-20 20:31:03 +00:00
|
|
|
|
2020-02-05 20:02:53 +00:00
|
|
|
const dispatcher = serverQueue.connection
|
2020-03-03 20:58:37 +00:00
|
|
|
.play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false }), { seek: seek, bitrate: 1024, passes: 10, volume: 1, bassboost: serverQueue.bass })
|
2020-03-03 20:24:41 +00:00
|
|
|
.on("end", () => {
|
|
|
|
client.dispatcher.finish(client, serverQueue.endReason, guild);
|
2020-02-05 20:02:53 +00:00
|
|
|
});
|
|
|
|
dispatcher.on('start', () => {
|
|
|
|
dispatcher.player.streamingData.pausedTime = 0;
|
|
|
|
});
|
2020-02-06 20:06:40 +00:00
|
|
|
dispatcher.on('error', error => {
|
|
|
|
console.error(error);
|
2020-03-03 20:24:41 +00:00
|
|
|
client.debug_channel.send('Error with the dispatcher: ' + error);
|
2020-02-06 20:06:40 +00:00
|
|
|
serverQueue.voiceChannel.leave();
|
|
|
|
client.queue.delete(guild.id);
|
|
|
|
return serverQueue.textChannel.send('<:redx:674263474704220182> An error has occured while playing music! The queue has been deleted.');
|
|
|
|
});
|
2020-02-05 20:02:53 +00:00
|
|
|
dispatcher.setVolume(serverQueue.volume / 10);
|
|
|
|
if (client.global.db.guilds[guild.id].startPlaying || play) {
|
|
|
|
const data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
|
|
|
|
const songtime = (data.length_seconds * 1000).toFixed(0);
|
|
|
|
const thumbnail = getThumb(serverQueue.songs[0].url);
|
|
|
|
const embed = new Discord.MessageEmbed()
|
|
|
|
.setTitle(`<a:aNotes:674602408105476106> Start playing: **${song.title}**`)
|
2020-02-10 19:07:09 +00:00
|
|
|
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
|
2020-02-05 20:02:53 +00:00
|
|
|
.setThumbnail(thumbnail._rejectionHandler0)
|
2020-02-05 20:26:18 +00:00
|
|
|
.setColor(client.config.embedColor)
|
2020-02-05 20:02:53 +00:00
|
|
|
serverQueue.textChannel.send(embed);
|
|
|
|
}
|
|
|
|
serverQueue.playing = true;
|
|
|
|
}
|