2019-09-15 06:18:33 +00:00
|
|
|
module.exports = async function (video, message, voiceChannel, client, playlist = false) {
|
|
|
|
const Discord = require('discord.js');
|
|
|
|
let song = {
|
|
|
|
id: video.id,
|
|
|
|
title: Discord.Util.escapeMarkdown(video.title),
|
|
|
|
url: `https://www.youtube.com/watch?v=${video.id}`
|
|
|
|
}
|
|
|
|
const serverQueue = client.queue.get(message.guild.id);
|
2019-10-10 13:43:04 +00:00
|
|
|
if (client.global.db.musix_guilds[message.guild.id].defaultVolume === undefined) {
|
|
|
|
client.global.db.musix_guilds[message.guild.id] = {
|
|
|
|
musix_prefix: client.global.db.musix_guilds[message.guild.id].musix_prefix,
|
|
|
|
defaultVolume: 5,
|
|
|
|
};
|
|
|
|
return message.channel.send(':x: `Error:` the default volume is undefined for this server. Please try again after a while.');
|
|
|
|
}
|
|
|
|
if (!serverQueue) {
|
|
|
|
const construct = {
|
2019-09-15 06:18:33 +00:00
|
|
|
textChannel: message.channel,
|
|
|
|
voiceChannel: voiceChannel,
|
|
|
|
connection: null,
|
|
|
|
songs: [],
|
2019-10-10 13:43:04 +00:00
|
|
|
volume: client.global.db.musix_guilds[message.guild.id].defaultVolume,
|
|
|
|
playing: true,
|
|
|
|
looping: false
|
2019-09-15 06:18:33 +00:00
|
|
|
};
|
2019-10-10 13:43:04 +00:00
|
|
|
construct.songs.push(song);
|
|
|
|
client.queue.set(message.guild.id, construct);
|
2019-09-15 06:18:33 +00:00
|
|
|
try {
|
|
|
|
var connection = await voiceChannel.join();
|
2019-10-10 13:43:04 +00:00
|
|
|
construct.connection = connection;
|
|
|
|
client.funcs.play(message.guild, construct.songs[0], client, message, 0);
|
2019-09-15 06:18:33 +00:00
|
|
|
} catch (error) {
|
|
|
|
client.queue.delete(message.guild.id);
|
|
|
|
return message.channel.send(`:x: An error occured: ${error}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
serverQueue.songs.push(song);
|
2019-10-10 13:43:04 +00:00
|
|
|
if (serverQueue.looping) {
|
|
|
|
client.secondaryQueue.push(song);
|
|
|
|
}
|
2019-09-15 06:18:33 +00:00
|
|
|
if (playlist) return undefined;
|
|
|
|
return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|