mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 22:15:37 +00:00
134 lines
6.0 KiB
JavaScript
134 lines
6.0 KiB
JavaScript
const logger = require('../../services/logger');
|
|
const { embedOptions } = require('../../config');
|
|
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
|
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
|
const { useQueue } = require('discord-player');
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('skip')
|
|
.setDescription('Skip current or specified track.')
|
|
.setDMPermission(false)
|
|
.addNumberOption((option) =>
|
|
option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1)
|
|
),
|
|
execute: async ({ interaction }) => {
|
|
if (await notInVoiceChannel(interaction)) {
|
|
return;
|
|
}
|
|
|
|
const queue = useQueue(interaction.guild.id);
|
|
|
|
if (await queueDoesNotExist(interaction, queue)) {
|
|
return;
|
|
}
|
|
|
|
if (await queueNoCurrentTrack(interaction, queue)) {
|
|
return;
|
|
}
|
|
|
|
const skipToTrack = interaction.options.getNumber('tracknumber');
|
|
|
|
if (skipToTrack) {
|
|
if (skipToTrack > queue.tracks.data.length) {
|
|
logger.debug(
|
|
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
|
|
);
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
`**${embedOptions.icons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with **\`/queue\`**.`
|
|
)
|
|
.setColor(embedOptions.colors.warning)
|
|
]
|
|
});
|
|
} else {
|
|
const skippedTrack = queue.currentTrack;
|
|
let durationFormat =
|
|
skippedTrack.raw.duration === 0 || skippedTrack.duration === '0:00'
|
|
? ''
|
|
: `\`${skippedTrack.duration}\``;
|
|
queue.node.skipTo(skipToTrack - 1);
|
|
|
|
logger.debug(
|
|
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped to track.`
|
|
);
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.member.nickname || interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**`
|
|
)
|
|
.setThumbnail(skippedTrack.thumbnail)
|
|
.setColor(embedOptions.colors.success)
|
|
]
|
|
});
|
|
}
|
|
} else {
|
|
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
|
|
logger.debug(
|
|
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no tracks in queue or current track.`
|
|
);
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
`**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
|
|
)
|
|
.setColor(embedOptions.colors.warning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const skippedTrack = queue.currentTrack;
|
|
let durationFormat =
|
|
skippedTrack.raw.duration === 0 || skippedTrack.duration === '0:00'
|
|
? ''
|
|
: `\`${skippedTrack.duration}\``;
|
|
queue.node.skip();
|
|
|
|
const loopModesFormatted = new Map([
|
|
[0, 'disabled'],
|
|
[1, 'track'],
|
|
[2, 'queue'],
|
|
[3, 'autoplay']
|
|
]);
|
|
|
|
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
|
|
|
logger.debug(
|
|
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped track.`
|
|
);
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.member.nickname || interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` +
|
|
`${
|
|
queue.repeatMode === 0
|
|
? ''
|
|
: `\n\n**${
|
|
queue.repeatMode === 3
|
|
? embedOptions.icons.autoplaying
|
|
: embedOptions.icons.looping
|
|
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.`
|
|
}`
|
|
)
|
|
.setThumbnail(skippedTrack.thumbnail)
|
|
.setColor(embedOptions.colors.success)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
};
|