From 4a7bf9ecb9dce1b6c61e57a4f4820217f7d876c8 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 6 Jul 2023 09:45:50 +0200 Subject: [PATCH] Updated interaction reply to have embed with color --- commands/pause.js | 24 +++++++--- commands/play.js | 13 ++++-- commands/queue.js | 114 ++++++++++++++++++++++++++++++---------------- index.js | 12 +++-- 4 files changed, 113 insertions(+), 50 deletions(-) diff --git a/commands/pause.js b/commands/pause.js index 566e9e3..1d9f4d6 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -8,17 +8,27 @@ module.exports = { .setDescription('Pause the currently playing track.'), run: async ({ interaction }) => { if (!interaction.member.voice.channel) { - return interaction.editReply( - 'You need to be in a voice channel to use this command.' - ); + return interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `You need to be in a voice channel to use this command.` + ) + .setColor('#c70057') + ] + }); } const queue = useQueue(interaction.guild.id); if (!queue) { - return await interaction.editReply( - 'There are no tracks in the queue.' - ); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription(`There are no tracks in the queue.`) + .setColor('#c70057') + ] + }); } // change paused state to opposite of current state @@ -35,6 +45,7 @@ module.exports = { `**Paused**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` ) .setThumbnail(queue.currentTrack.thumbnail) + .setColor('#4c73df') ] }); } else { @@ -49,6 +60,7 @@ module.exports = { `**Resumed**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` ) .setThumbnail(queue.currentTrack.thumbnail) + .setColor('#4c73df') ] }); } diff --git a/commands/play.js b/commands/play.js index 0dea4e1..97f956a 100644 --- a/commands/play.js +++ b/commands/play.js @@ -14,9 +14,15 @@ module.exports = { ), run: async ({ interaction }) => { if (!interaction.member.voice.channel) { - return interaction.editReply( - 'You need to be in a voice channel to use this command.' - ); + return interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `You need to be in a voice channel to use this command.` + ) + .setColor('#c70057') + ] + }); } const player = useMainPlayer(); @@ -48,6 +54,7 @@ module.exports = { `**Added to queue**\n\`[${track.duration}]\` **[${track.title}](${track.url})**` ) .setThumbnail(track.thumbnail) + .setColor('#4c73df') ] }); } catch (e) { diff --git a/commands/queue.js b/commands/queue.js index f14082f..2978ea0 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); -const { useMainPlayer, useQueue } = require('discord-player'); +const { useQueue } = require('discord-player'); const { EmbedBuilder } = require('discord.js'); module.exports = { @@ -14,30 +14,50 @@ module.exports = { ), run: async ({ interaction }) => { if (!interaction.member.voice.channel) { - return interaction.editReply( - 'You need to be in a voice channel to use this command.' - ); + return interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `You need to be in a voice channel to use this command.` + ) + .setColor('#c70057') + ] + }); } const queue = useQueue(interaction.guild.id); + let queueString = ''; if (!queue) { - return await interaction.editReply( - 'There are no tracks in the queue.' - ); + queueString = 'There are no tracks in the queue.'; + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.guild.name, + iconURL: interaction.guild.iconURL() + }) + .setDescription(`**Queue**\n${queueString}`) + .setColor('#4c73df') + ] + }); } const totalPages = Math.ceil(queue.tracks.data.length / 10) || 1; const page = (interaction.options.getNumber('page') || 1) - 1; if (page > totalPages - 1) { - return await interaction.editReply( - `Invalid page number. There are only a total of ${totalPages} pages of tracks.` - ); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `Invalid page number. There are only a total of ${totalPages} pages of tracks.` + ) + .setColor('#c70057') + ] + }); } - let queueString = ''; - if (queue.tracks.data.length === 0) { queueString = 'There are no tracks in the queue.'; } else { @@ -53,32 +73,50 @@ module.exports = { let currentTrack = queue.currentTrack; - let bar = queue.node.createProgressBar({ - queue: false, - length: 13 - }); + if (!currentTrack) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.guild.name, + iconURL: interaction.guild.iconURL() + }) + .setDescription(`**Queue**\n${queueString}`) + .setFooter({ + text: `Page ${page + 1} of ${totalPages}` + }) + .setColor('#4c73df') + ] + }); + } else { + let bar = queue.node.createProgressBar({ + queue: false, + length: 13 + }); - await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setAuthor({ - name: interaction.guild.name, - iconURL: interaction.guild.iconURL() - }) - .setDescription( - `**Currently playing**\n` + - (currentTrack - ? `**[${currentTrack.title}](${currentTrack.url})**` - : 'None') + - `\nRequested by: <@${currentTrack.requestedBy.id}>` + - `\n ${bar}` + - `\n\n**Queue**\n${queueString}` - ) - .setThumbnail(queue.currentTrack.thumbnail) - .setFooter({ - text: `Page ${page + 1} of ${totalPages}` - }) - ] - }); + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.guild.name, + iconURL: interaction.guild.iconURL() + }) + .setDescription( + `**Currently playing**\n` + + (currentTrack + ? `**[${currentTrack.title}](${currentTrack.url})**` + : 'None') + + `\nRequested by: <@${currentTrack.requestedBy.id}>` + + `\n ${bar}` + + `\n\n**Queue**\n${queueString}` + ) + .setThumbnail(queue.currentTrack.thumbnail) + .setFooter({ + text: `Page ${page + 1} of ${totalPages}` + }) + .setColor('#4c73df') + ] + }); + } } }; diff --git a/index.js b/index.js index a8543c9..443a9f4 100644 --- a/index.js +++ b/index.js @@ -76,9 +76,15 @@ client.on('interactionCreate', async (interaction) => { `Command '/${interaction.commandName}' failed unexpectedly.` ); - await interaction.editReply( - 'There was an error while executing this command!' - ); + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `There was an error while executing this command!` + ) + .setColor('#c70057') + ] + }); } });