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

@@ -9,6 +9,7 @@ async function getMusicStream(query) {
let songTitle;
let songDuration;
let type = StreamType.Opus;
let userInput = query;
if (query.includes('spotify.com')) {
stream = await spotify.getStream(query);
@@ -34,6 +35,7 @@ async function getMusicStream(query) {
return {
title: songTitle,
duration: songDuration,
userInput: userInput,
stream: stream,
type: type
};

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;

View File

@@ -28,12 +28,7 @@ async function registerCommands(clientId, token) {
.setDescription('Resumes the current song!'),
new SlashCommandBuilder()
.setName('loop')
.setDescription('Loops the current song!')
.addBooleanOption(option =>
option.setName('looping')
.setDescription('Enable or disable looping')
.setRequired(true)
)
.setDescription('Loops the current song! (toggle)'),
];
const rest = new REST({ version: '9' }).setToken(token);