mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: Updated user messages for /queue command
This commit is contained in:
1 parent
c4f14ef6ba
commit
ee11b712a0
1 file changed
+38
-19
+38
-19
@@ -1,7 +1,11 @@
|
|||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { useQueue } = require('discord-player');
|
const { useQueue } = require('discord-player');
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const { embedColors, progressBarOptions } = require('../config.json');
|
const {
|
||||||
|
embedColors,
|
||||||
|
embedIcons,
|
||||||
|
progressBarOptions
|
||||||
|
} = require('../config.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@@ -20,19 +24,31 @@ module.exports = {
|
|||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
'**Failed**\nYou need to be in a voice channel to use this command.'
|
`**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.`
|
||||||
)
|
)
|
||||||
.setColor(embedColors.colorWarning)
|
.setColor(embedColors.colorWarning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
||||||
const queue = useQueue(interaction.guild.id);
|
const queue = useQueue(interaction.guild.id);
|
||||||
let queueString = '';
|
let queueString = '';
|
||||||
|
|
||||||
if (!queue) {
|
if (!queue) {
|
||||||
queueString =
|
if (pageIndex >= 1) {
|
||||||
'There are no tracks in the queue. Add tracks with `/play`!';
|
return await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setDescription(
|
||||||
|
`**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with \`/play\`!`
|
||||||
|
)
|
||||||
|
.setColor(embedColors.colorWarning)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
queueString = 'The queue is empty, add some tracks with `/play`!';
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
@@ -40,7 +56,9 @@ module.exports = {
|
|||||||
name: interaction.guild.name,
|
name: interaction.guild.name,
|
||||||
iconURL: interaction.guild.iconURL()
|
iconURL: interaction.guild.iconURL()
|
||||||
})
|
})
|
||||||
.setDescription(`**Queue**\n${queueString}`)
|
.setDescription(
|
||||||
|
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
|
||||||
|
)
|
||||||
.setColor(embedColors.colorInfo)
|
.setColor(embedColors.colorInfo)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: 'Page 1 of 1'
|
text: 'Page 1 of 1'
|
||||||
@@ -50,34 +68,33 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1;
|
const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1;
|
||||||
const page = (interaction.options.getNumber('page') || 1) - 1;
|
|
||||||
|
|
||||||
if (page > totalPages - 1) {
|
if (pageIndex > totalPages - 1) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**Error**\nInvalid page number. There are only a total of \`${totalPages}\` pages of tracks.`
|
`**${embedIcons.warning} Oops!**\nPage \`${pageIndex + 1}\` is not a valid page number.\n\nThere are only a total of \`${totalPages}\` pages in the queue.`
|
||||||
)
|
)
|
||||||
.setColor(embedColors.colorError)
|
.setColor(embedColors.colorWarning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue.tracks.data.length === 0) {
|
if (queue.tracks.data.length === 0) {
|
||||||
queueString = 'There are no tracks in the queue.';
|
queueString = 'The queue is empty, add some tracks with `/play`!';
|
||||||
} else {
|
} else {
|
||||||
queueString = queue.tracks.data
|
queueString = queue.tracks.data
|
||||||
.slice(page * 10, page * 10 + 10)
|
.slice(pageIndex * 10, pageIndex * 10 + 10)
|
||||||
.map((track, index) => {
|
.map((track, index) => {
|
||||||
let durationFormat =
|
let durationFormat =
|
||||||
track.raw.duration === 0 || track.duration === '0:00'
|
track.raw.duration === 0 || track.duration === '0:00'
|
||||||
? ''
|
? ''
|
||||||
: `\`${track.duration}\``;
|
: `\`${track.duration}\``;
|
||||||
|
|
||||||
return `**${page * 10 + index + 1}.** ${durationFormat} [${
|
return `**${pageIndex * 10 + index + 1}.** ${durationFormat} **[${
|
||||||
track.title
|
track.title
|
||||||
}](${track.url})`;
|
}](${track.url})**`;
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
}
|
}
|
||||||
@@ -94,9 +111,11 @@ module.exports = {
|
|||||||
}kbps)`,
|
}kbps)`,
|
||||||
iconURL: interaction.guild.iconURL()
|
iconURL: interaction.guild.iconURL()
|
||||||
})
|
})
|
||||||
.setDescription(`**Queue**\n${queueString}`)
|
.setDescription(
|
||||||
|
`**${embedIcons.queue} Tracks in queue**\n${queueString}`
|
||||||
|
)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Page ${page + 1} of ${totalPages}`
|
text: `Page ${pageIndex + 1} of ${totalPages}`
|
||||||
})
|
})
|
||||||
.setColor(embedColors.colorInfo)
|
.setColor(embedColors.colorInfo)
|
||||||
]
|
]
|
||||||
@@ -118,7 +137,7 @@ module.exports = {
|
|||||||
currentTrack.raw.duration === 0 ||
|
currentTrack.raw.duration === 0 ||
|
||||||
currentTrack.duration === '0:00'
|
currentTrack.duration === '0:00'
|
||||||
) {
|
) {
|
||||||
bar = 'No duration available.';
|
bar = '_No duration available._';
|
||||||
}
|
}
|
||||||
|
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -131,17 +150,17 @@ module.exports = {
|
|||||||
iconURL: interaction.guild.iconURL()
|
iconURL: interaction.guild.iconURL()
|
||||||
})
|
})
|
||||||
.setDescription(
|
.setDescription(
|
||||||
'**Currently playing**\n' +
|
`**${embedIcons.audioPlaying} Now playing**\n` +
|
||||||
(currentTrack
|
(currentTrack
|
||||||
? `**[${currentTrack.title}](${currentTrack.url})**`
|
? `**[${currentTrack.title}](${currentTrack.url})**`
|
||||||
: 'None') +
|
: 'None') +
|
||||||
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
|
`\nRequested by: <@${currentTrack.requestedBy.id}>` +
|
||||||
`\n ${bar}` +
|
`\n ${bar}` +
|
||||||
`\n\n**Queue**\n${queueString}`
|
`\n\n**${embedIcons.queue} Tracks in queue**\n${queueString}`
|
||||||
)
|
)
|
||||||
.setThumbnail(queue.currentTrack.thumbnail)
|
.setThumbnail(queue.currentTrack.thumbnail)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Page ${page + 1} of ${totalPages}`
|
text: `Page ${pageIndex + 1} of ${totalPages}`
|
||||||
})
|
})
|
||||||
.setColor(embedColors.colorInfo)
|
.setColor(embedColors.colorInfo)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in new issue
Block a user