Pause resume loop
This commit is contained in:
@@ -24,10 +24,10 @@ async function getMusicStream(query) {
|
||||
type = StreamType.OggOpus;
|
||||
|
||||
} else {
|
||||
stream = await youtube.getStream(query);
|
||||
songTitle = stream.title ?? 'Unknown';
|
||||
songDuration = stream.duration ?? 'Unknown';
|
||||
stream = stream.stream;
|
||||
stream = await youtube.getStream(query)
|
||||
songTitle = stream?.title ?? 'Unknown';
|
||||
songDuration = stream?.duration ?? 'Unknown';
|
||||
stream = stream?.stream;
|
||||
type = StreamType.Opus;
|
||||
}
|
||||
|
||||
|
||||
67
utils/musicPlayer.js
Normal file
67
utils/musicPlayer.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const {
|
||||
createAudioResource,
|
||||
createAudioPlayer,
|
||||
NoSubscriberBehavior,
|
||||
AudioPlayerStatus,
|
||||
} = require('@discordjs/voice');
|
||||
const musicQueue = require('../musicQueue');
|
||||
|
||||
async function musicPlayer(guildId, connection) {
|
||||
const serverQueue = musicQueue.getQueue(guildId);
|
||||
|
||||
if (serverQueue.length === 0) {
|
||||
connection.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
const song = serverQueue[0];
|
||||
|
||||
if(song.stream == null){
|
||||
musicQueue.removeFromQueue(guildId);
|
||||
musicPlayer(guildId, connection);
|
||||
return;
|
||||
}
|
||||
|
||||
let resource = createAudioResource(song.stream, {
|
||||
inputType: song.type
|
||||
})
|
||||
|
||||
let player = createAudioPlayer({
|
||||
behaviors: {
|
||||
noSubscriber: NoSubscriberBehavior.Play
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
player.play(resource)
|
||||
|
||||
connection.subscribe(player)
|
||||
|
||||
player.on(AudioPlayerStatus.Idle, () => {
|
||||
console.log('Song ended:', song.title);
|
||||
musicQueue.removeFromQueue(guildId);
|
||||
musicPlayer(guildId, connection);
|
||||
});
|
||||
|
||||
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;
|
||||
@@ -19,7 +19,21 @@ async function registerCommands(clientId, token) {
|
||||
option.setName('song')
|
||||
.setDescription('Add song from YouTube, Spotify, SoundCloud, etc. to the queue')
|
||||
.setRequired(true)
|
||||
)
|
||||
),
|
||||
new SlashCommandBuilder()
|
||||
.setName('pause')
|
||||
.setDescription('Pauses the current song!'),
|
||||
new SlashCommandBuilder()
|
||||
.setName('resume')
|
||||
.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)
|
||||
)
|
||||
];
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
Reference in New Issue
Block a user