Creating functional loop, pause and unpause

This commit is contained in:
Azaaxin
2023-06-25 04:00:21 +02:00
parent 35eb54ab8c
commit dddbe81fab
12 changed files with 106 additions and 74 deletions

View File

@@ -6,7 +6,7 @@ const {
} = require('@discordjs/voice');
const musicQueue = require('../musicQueue');
async function musicPlayer(guildId, connection) {
async function musicPlayer(guildId, connection, interaction) {
const serverQueue = musicQueue.getQueue(guildId);
if (serverQueue.length === 0) {
@@ -31,37 +31,21 @@ async function musicPlayer(guildId, connection) {
noSubscriber: NoSubscriberBehavior.Play
}
})
player.play(resource)
connection.subscribe(player)
player.on(AudioPlayerStatus.Idle, () => {
interaction.followUp(`Added **${song.title}** to the queue.`).then(message =>
setTimeout(() =>
message.delete(),
song.duration + 10000));
player.on(AudioPlayerStatus.Idle, async () => {
console.log('Song ended:', song.title);
musicQueue.removeFromQueue(guildId);
musicPlayer(guildId, connection);
await musicQueue.removeFromQueue(guildId)
});
return player;
}
// TODO: USE THIS AGAIN
function convertToMilliseconds(songLenth) {
try {
let time = songLenth.split(':')
let milliseconds = 0;
if(time.length == 3) {
milliseconds = (parseInt(time[0]) * 60 * 60 * 1000) + (parseInt(time[1]) * 60 * 1000) + (parseInt(time[2]) * 1000)
} else if(time.length == 2) {
milliseconds = (parseInt(time[0]) * 60 * 1000) + (parseInt(time[1]) * 1000)
} else if(time.length == 1) {
milliseconds = (parseInt(time[0]) * 1000)
}
return milliseconds
} catch (error) {
return 10000;
}
}
module.exports.musicPlayer = musicPlayer;