1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-22 21:13:18 +00:00
musix-oss/funcs/handleVideo.js

54 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-02-09 09:53:30 +00:00
const { createAudioPlayer, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require("@discordjs/voice");
2019-09-15 06:18:33 +00:00
module.exports = async function (video, message, voiceChannel, client, playlist = false) {
let song = {
id: video.id,
2024-03-06 00:32:44 +00:00
title: he.decode(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,
2024-02-09 09:53:30 +00:00
audioPlayer: createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
}),
2019-09-15 06:18:33 +00:00
songs: [],
2019-10-11 08:48:50 +00:00
volume: client.global.db.guilds[message.guild.id].defaultVolume,
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 {
2024-02-09 09:53:30 +00:00
const connection =
getVoiceConnection(voiceChannel.guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
2019-10-10 13:43:04 +00:00
construct.connection = connection;
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);
2024-02-09 09:53:30 +00:00
console.log("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
}