1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-16 12:36:01 +00:00

Fix code to work on this decade 1/x

This commit is contained in:
Christer Warén
2024-02-09 11:53:30 +02:00
parent d609687957
commit 9049a5e6b8
53 changed files with 2455 additions and 1704 deletions

53
funcs/handleVideo.js Normal file
View File

@ -0,0 +1,53 @@
const { createAudioPlayer, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require("@discordjs/voice");
module.exports = async function (video, message, voiceChannel, client, playlist = false) {
let song = {
id: video.id,
title: video.title,
url: `https://www.youtube.com/watch?v=${video.id}`,
author: message.author
}
const serverQueue = client.queue.get(message.guild.id);
if (!serverQueue) {
const construct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
audioPlayer: createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
}),
songs: [],
volume: client.global.db.guilds[message.guild.id].defaultVolume,
playing: false,
paused: false,
looping: false,
votes: 0,
voters: [],
votesNeeded: null
};
construct.songs.push(song);
client.queue.set(message.guild.id, construct);
try {
const connection =
getVoiceConnection(voiceChannel.guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
client.funcs.play(message.guild, construct.songs[0], client, message, 0, true);
} catch (error) {
client.queue.delete(message.guild.id);
console.log("Error with connecting to voice channel: " + error);
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;
}