mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 22:14:59 +00:00
119 lines
4.6 KiB
JavaScript
119 lines
4.6 KiB
JavaScript
const { SlashCommandBuilder } = require('@discordjs/builders');
|
|
const { useQueue } = require('discord-player');
|
|
const { EmbedBuilder } = require('discord.js');
|
|
const { embedColors } = require('../config.json');
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('skip')
|
|
.setDescription('Skip the current track.')
|
|
.setDMPermission(false)
|
|
.addNumberOption((option) =>
|
|
option
|
|
.setName('tracknumber')
|
|
.setDescription('Track number to skip to in the queue.')
|
|
.setMinValue(1)
|
|
),
|
|
run: async ({ interaction }) => {
|
|
if (!interaction.member.voice.channel) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Failed**\nYou need to be in a voice channel to use this command.'
|
|
)
|
|
.setColor(embedColors.colorWarning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const queue = useQueue(interaction.guild.id);
|
|
|
|
if (!queue) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
|
|
)
|
|
.setColor(embedColors.colorWarning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const skipToTrack = interaction.options.getNumber('tracknumber');
|
|
|
|
if (skipToTrack) {
|
|
if (skipToTrack > queue.tracks.data.length) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
`**Error**\nThere are \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track number \`${skipToTrack}\`.`
|
|
)
|
|
.setColor(embedColors.colorError)
|
|
]
|
|
});
|
|
} else {
|
|
const skippedTrack = queue.currentTrack;
|
|
let durationFormat =
|
|
skippedTrack.raw.duration === 0 ||
|
|
skippedTrack.duration === '0:00'
|
|
? ''
|
|
: `\`${skippedTrack.duration}\``;
|
|
queue.node.skipTo(skipToTrack - 1);
|
|
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.`
|
|
)
|
|
.setThumbnail(skippedTrack.thumbnail)
|
|
.setColor(embedColors.colorSuccess)
|
|
]
|
|
});
|
|
}
|
|
} else {
|
|
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Failed**\nThere are no tracks in the queue and nothing currently playing.'
|
|
)
|
|
.setColor(embedColors.colorWarning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const skippedTrack = queue.currentTrack;
|
|
let durationFormat =
|
|
skippedTrack.raw.duration === 0 ||
|
|
skippedTrack.duration === '0:00'
|
|
? ''
|
|
: `\`${skippedTrack.duration}\``;
|
|
queue.node.skip();
|
|
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**.`
|
|
)
|
|
.setThumbnail(skippedTrack.thumbnail)
|
|
.setColor(embedColors.colorSuccess)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
};
|