60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
const { Client, Interaction, SlashCommandBuilder } = require('discord.js')
|
|
|
|
const { playFromQueue, queue } = require('../../playback');
|
|
const { getVoiceConnection } = require('@discordjs/voice')
|
|
|
|
async function skipSong(voiceChannel, textChannel) {
|
|
const connection = getVoiceConnection(voiceChannel.guild.id)
|
|
|
|
if (!connection) {
|
|
console.log('No active voice connections')
|
|
textChannel.send('No active voice connections')
|
|
return
|
|
}
|
|
|
|
if (!queue || queue.length === 0) {
|
|
console.log('Queue is empty. No songs to skip')
|
|
connection.state.subscription.player.stop();
|
|
return;
|
|
}
|
|
|
|
try {
|
|
queue.shift()
|
|
|
|
if (queue.length > 0 ) {
|
|
const nextSong = queue[0];
|
|
await playFromQueue(voiceChannel, textChannel, nextSong.getMember, nextSong.link, nextSong.songName)
|
|
} else {
|
|
textChannel.send('No more songs in the queue')
|
|
}
|
|
} catch (error) {
|
|
console.error('Error skipping song: ', error)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('skip')
|
|
.setDescription('Skips a song in the queue'),
|
|
async execute(interaction) {
|
|
const voiceChannel = interaction.member.voice.channel
|
|
const textChannel = interaction.channel
|
|
if (!voiceChannel) {
|
|
return interaction.reply({
|
|
content: 'You need to be in a voice channel to use the command',
|
|
ephemeral: true
|
|
});
|
|
}
|
|
|
|
try {
|
|
await skipSong(voiceChannel, textChannel)
|
|
interaction.reply('Skipped the current song')
|
|
} catch (error) {
|
|
console.error('Error in skip command: ', error)
|
|
interaction.reply({
|
|
content: 'An error has occurred while processing the command',
|
|
ephemeral: true
|
|
});
|
|
}
|
|
}
|
|
} |