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),
|
2019-10-24 16:29:04 +00:00
|
|
|
url: `https://www.youtube.com/watch?v=${video.id}`,
|
|
|
|
author: message.author
|
2019-09-15 06:18:33 +00:00
|
|
|
}
|
|
|
|
const serverQueue = client.queue.get(message.guild.id);
|
2019-10-10 13:43:04 +00:00
|
|
|
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-11-22 18:51:41 +00:00
|
|
|
playing: false,
|
|
|
|
paused: false,
|
2019-11-19 13:59:14 +00:00
|
|
|
looping: false,
|
|
|
|
votes: 0,
|
|
|
|
voters: [],
|
|
|
|
votesNeeded: null
|
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;
|
2019-10-24 17:11:08 +00:00
|
|
|
client.funcs.play(message.guild, construct.songs[0], client, message, 0, true);
|
2019-09-15 06:18:33 +00:00
|
|
|
} catch (error) {
|
|
|
|
client.queue.delete(message.guild.id);
|
2019-10-31 19:09:35 +00:00
|
|
|
client.channels.get(client.config.debug_channel).send("Error with connecting to voice channel: " + error);
|
2019-09-15 06:18:33 +00:00
|
|
|
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;
|
2019-10-31 19:09:35 +00:00
|
|
|
}
|