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-11 11:30:10 +00:00
|
|
|
if (client.global.db.guilds[message.guild.id].defaultVolume === undefined) {
|
2019-10-11 08:48:50 +00:00
|
|
|
client.global.db.guilds[message.guild.id] = {
|
|
|
|
prefix: client.global.db.guilds[message.guild.id].prefix,
|
2019-10-10 13:43:04 +00:00
|
|
|
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-11 08:48:50 +00:00
|
|
|
volume: client.global.db.guilds[message.guild.id].defaultVolume,
|
2019-10-10 13:43:04 +00:00
|
|
|
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);
|
|
|
|
if (playlist) return undefined;
|
|
|
|
return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|