1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 14:01:55 +00:00
musix-oss/struct/funcs/handleVideo.js

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-02-05 20:02:53 +00:00
module.exports = async function (video, msg, voiceChannel, client, playlist = false) {
const Discord = require('discord.js');
const song = {
id: video.id,
title: Discord.Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`,
author: msg.author
}
2020-03-03 20:24:41 +00:00
2020-02-05 20:02:53 +00:00
const serverQueue = client.queue.get(msg.guild.id);
2020-03-03 20:24:41 +00:00
2020-02-05 20:02:53 +00:00
if (serverQueue) {
serverQueue.songs.push(song);
if (playlist) return;
return msg.channel.send(`<:green_check_mark:674265384777416705> **${song.title}** has been added to the queue!`);
}
2020-03-03 20:24:41 +00:00
const construct = require("../config/queueConfig.js");
2020-03-04 20:27:14 +00:00
2020-03-03 20:24:41 +00:00
construct.textChannel = msg.channel;
construct.voiceChannel = voiceChannel;
construct.volume = client.global.db.guilds[msg.guild.id].defaultVolume;
construct.bass = client.global.db.guilds[msg.guild.id].bass;
2020-02-05 20:02:53 +00:00
construct.songs.push(song);
2020-03-04 20:27:14 +00:00
2020-02-05 20:02:53 +00:00
client.queue.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
2020-03-03 20:24:41 +00:00
client.debug_channel.send("Error with connecting to voice channel: " + error);
2020-02-05 20:02:53 +00:00
return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`);
}
return;
}