From f59055807f9a7170edab5d476e370575ba09803a Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 27 Jul 2023 21:58:09 +0200 Subject: [PATCH 1/5] fix: Improvement to play command autocomplete search --- src/commands/player/play.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commands/player/play.js b/src/commands/player/play.js index b2d6f46..6a0e0ad 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -30,10 +30,11 @@ module.exports = { return; } const searchResults = await player.search(query); + let response = []; logger.debug(`[Shard ${interaction.guild.shardId}] Autocomplete search responded for query: ${query}`); - let response = searchResults.tracks.slice(0, 5).map((track) => ({ + response = searchResults.tracks.slice(0, 5).map((track) => ({ name: `${track.title} [Author: ${track.author}]`.length > 100 ? `${track.title}`.slice(0, 100) @@ -41,6 +42,10 @@ module.exports = { value: track.url })); + if (!response || response.length === 0) { + return interaction.respond([]); + } + return interaction.respond(response); }, execute: async ({ interaction }) => { From 311e1419922c4fc7a02952bda772ce705e567736 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 27 Jul 2023 22:59:13 +0200 Subject: [PATCH 2/5] fix: Also validate is user is in same voice channel as bot for commands --- src/commands/player/filters.js | 6 ++++- src/commands/player/leave.js | 6 ++++- src/commands/player/loop.js | 6 ++++- src/commands/player/nowplaying.js | 6 ++++- src/commands/player/pause.js | 6 ++++- src/commands/player/play.js | 13 +++++++--- src/commands/player/queue.js | 7 +++++- src/commands/player/remove.js | 6 ++++- src/commands/player/seek.js | 6 ++++- src/commands/player/shuffle.js | 6 ++++- src/commands/player/skip.js | 6 ++++- src/commands/player/stop.js | 6 ++++- src/commands/player/volume.js | 6 ++++- src/utils/validation/voiceChannelValidator.js | 25 ++++++++++++++++++- 14 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/commands/player/filters.js b/src/commands/player/filters.js index 77573ac..2b6efa1 100644 --- a/src/commands/player/filters.js +++ b/src/commands/player/filters.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, ffmpegFilterOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, @@ -31,6 +31,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueNoCurrentTrack(interaction, queue)) { return; } diff --git a/src/commands/player/leave.js b/src/commands/player/leave.js index 713a049..b8226c0 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -34,6 +34,10 @@ module.exports = { }); } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (!queue.deleted) { queue.delete(); logger.debug( diff --git a/src/commands/player/loop.js b/src/commands/player/loop.js index 87ec55b..d727a00 100644 --- a/src/commands/player/loop.js +++ b/src/commands/player/loop.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, botOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -36,6 +36,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + const loopModesFormatted = new Map([ [0, 'disabled'], [1, 'track'], diff --git a/src/commands/player/nowplaying.js b/src/commands/player/nowplaying.js index e684954..7f9feab 100644 --- a/src/commands/player/nowplaying.js +++ b/src/commands/player/nowplaying.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, playerOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -24,6 +24,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueNoCurrentTrack(interaction, queue)) { return; } diff --git a/src/commands/player/pause.js b/src/commands/player/pause.js index 0a2c3c1..a5ff91a 100644 --- a/src/commands/player/pause.js +++ b/src/commands/player/pause.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -24,6 +24,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueNoCurrentTrack(interaction, queue)) { return; } diff --git a/src/commands/player/play.js b/src/commands/player/play.js index 6a0e0ad..6ccaa4f 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, playerOptions, botOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { cannotJoinVoiceOrTalk } = require('../../utils/validation/permissionValidator'); const { transformQuery } = require('../../utils/validation/searchQueryValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); @@ -48,8 +48,8 @@ module.exports = { return interaction.respond(response); }, - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, client }) => { + if (await notInVoiceChannel(interaction, client)) { return; } @@ -57,6 +57,11 @@ module.exports = { return; } + let queue = useQueue(interaction.guild.id); + if (queue && (await notInSameVoiceChannel(interaction, queue))) { + return; + } + const player = useMainPlayer(); const query = interaction.options.getString('query'); @@ -107,7 +112,7 @@ module.exports = { }); } - let queue = useQueue(interaction.guild.id); + queue = useQueue(interaction.guild.id); let queueSize = queue?.size ?? 0; if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) { diff --git a/src/commands/player/queue.js b/src/commands/player/queue.js index 9eebfd8..eb41e3f 100644 --- a/src/commands/player/queue.js +++ b/src/commands/player/queue.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions, playerOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -19,6 +19,11 @@ module.exports = { } const queue = useQueue(interaction.guild.id); + + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + const pageIndex = (interaction.options.getNumber('page') || 1) - 1; let queueString = ''; diff --git a/src/commands/player/remove.js b/src/commands/player/remove.js index e371dff..85b96bb 100644 --- a/src/commands/player/remove.js +++ b/src/commands/player/remove.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -31,6 +31,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + const removeTrackNumber = interaction.options.getNumber('tracknumber'); if (removeTrackNumber > queue.tracks.data.length) { diff --git a/src/commands/player/seek.js b/src/commands/player/seek.js index e5bd3f7..311ac75 100644 --- a/src/commands/player/seek.js +++ b/src/commands/player/seek.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -30,6 +30,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueNoCurrentTrack(interaction, queue)) { return; } diff --git a/src/commands/player/shuffle.js b/src/commands/player/shuffle.js index 06204eb..f74d2b1 100644 --- a/src/commands/player/shuffle.js +++ b/src/commands/player/shuffle.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueIsEmpty } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -24,6 +24,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueIsEmpty(interaction, queue)) { return; } diff --git a/src/commands/player/skip.js b/src/commands/player/skip.js index 18a1645..c217020 100644 --- a/src/commands/player/skip.js +++ b/src/commands/player/skip.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -27,6 +27,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (await queueNoCurrentTrack(interaction, queue)) { return; } diff --git a/src/commands/player/stop.js b/src/commands/player/stop.js index 7ac9ef4..3bc7d4d 100644 --- a/src/commands/player/stop.js +++ b/src/commands/player/stop.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -34,6 +34,10 @@ module.exports = { }); } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + if (!queue.deleted) { queue.setRepeatMode(0); queue.clear(); diff --git a/src/commands/player/volume.js b/src/commands/player/volume.js index efbaf4b..5c7fe9e 100644 --- a/src/commands/player/volume.js +++ b/src/commands/player/volume.js @@ -1,6 +1,6 @@ const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); -const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); const { queueDoesNotExist } = require('../../utils/validation/queueValidator'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); @@ -31,6 +31,10 @@ module.exports = { return; } + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + const volume = interaction.options.getNumber('percentage'); if (!volume && volume !== 0) { diff --git a/src/utils/validation/voiceChannelValidator.js b/src/utils/validation/voiceChannelValidator.js index 750e96e..8fc8509 100644 --- a/src/utils/validation/voiceChannelValidator.js +++ b/src/utils/validation/voiceChannelValidator.js @@ -8,7 +8,7 @@ exports.notInVoiceChannel = async (interaction) => { embeds: [ new EmbedBuilder() .setDescription( - `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Not in a voice channel**\nYou need to be in a voice channel to use this command.` ) .setColor(embedOptions.colors.warning) ] @@ -20,3 +20,26 @@ exports.notInVoiceChannel = async (interaction) => { return false; }; + +exports.notInSameVoiceChannel = async (interaction, queue) => { + if (!queue.dispatcher) { + return true; + } + + if (interaction.member.voice.channel.id !== queue.dispatcher.channel.id) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.warning} Not in same voice channel**\nYou need to be in the same voice channel as me to use this command.\n\n**Voice channel:** ${queue.dispatcher.channel.name}` + ) + .setColor(embedOptions.colors.warning) + ] + }); + + logger.debug(`User tried to use command ${interaction.commandName} but was not in the same voice channel.`); + return true; + } + + return false; +}; From 0887a47af94d3bc4b2e6865de8d41040c5369a24 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 27 Jul 2023 23:03:01 +0200 Subject: [PATCH 3/5] chore: remove comment and rewrite text --- src/commands/info/help.js | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/commands/info/help.js b/src/commands/info/help.js index a5e6496..869694a 100644 --- a/src/commands/info/help.js +++ b/src/commands/info/help.js @@ -31,37 +31,11 @@ module.exports = { .setDescription( `${embedOptions.icons.rule} **List of commands**\n` + `${commandListString}\n\n` + - `${embedOptions.icons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botOptions.serverInviteUrl}**\n\n` + + `${embedOptions.icons.support} **Support server**\nJoin the support server for help or to suggest improvements: \n**${botOptions.serverInviteUrl}**\n\n` + `${embedOptions.icons.bot} **Enjoying ${botOptions.name}?**\nAdd me to another server: \n**[Click me!](${botOptions.botInviteUrl})**` ) .setColor(embedOptions.colors.info) ] }); - - /* - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - `${embedOptions.icons.rule} **List of commands**\n` + - '- **`/play` `query`** - Add a track or playlist to the queue by url or search.\n' + - '- **`/pause`** - Pause or resume the current track.\n' + - '- **`/queue` `[page]`** - Show the list of tracks added to the queue.\n' + - '- **`/nowplaying`** - Show information about the track currently playing.\n' + - '- **`/seek` `duration`** - Seek to a specified duration in the current track.\n' + - `- **\`/loop\` \`mode\`** - ${embedOptions.icons.beta} Toggle looping a track, the whole queue or autoplay.\n` + - `- **\`/filters\`** - ${embedOptions.icons.beta} Toggle various audio filters during playback.\n` + - '- **`/volume` `[percentage]`** - Show or set the playback volume for tracks.\n' + - '- **`/skip` `[tracknumber]`** - Skip to next or specified track.\n' + - '- **`/remove` `tracknumber`** - Remove specified track from the queue.\n' + - `- **\`/stop\`** - ${embedOptions.icons.new} Stop playing audio and clear the track queue.\n` + - '- **`/leave`** - Clear the queue and remove the bot from voice channel.\n\n' + - `${embedOptions.icons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botOptions.serverInviteUrl}**\n\n` + - `${embedOptions.icons.bot} **Enjoying ${botOptions.name}?**\nAdd me to another server: \n**[Click me!](${botOptions.botInviteUrl})**` - ) - .setColor(embedOptions.colors.info) - ] - }); - */ } }; From 0d003a868bf509209400b56714aadab8b32ca3df Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 27 Jul 2023 23:03:11 +0200 Subject: [PATCH 4/5] chore: update isNew status for stop command --- src/commands/player/stop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/player/stop.js b/src/commands/player/stop.js index 3bc7d4d..6170031 100644 --- a/src/commands/player/stop.js +++ b/src/commands/player/stop.js @@ -5,7 +5,7 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { - isNew: true, + isNew: false, isBeta: false, data: new SlashCommandBuilder() .setName('stop') From 1dcc9e00b87935eead3b52899d360393b5c49792 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 27 Jul 2023 23:03:20 +0200 Subject: [PATCH 5/5] feat: Added /lyrics command --- src/commands/player/lyrics.js | 212 ++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 src/commands/player/lyrics.js diff --git a/src/commands/player/lyrics.js b/src/commands/player/lyrics.js new file mode 100644 index 0000000..941f0d1 --- /dev/null +++ b/src/commands/player/lyrics.js @@ -0,0 +1,212 @@ +const logger = require('../../services/logger'); +const { embedOptions } = require('../../config'); +const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); +const { useMainPlayer, useQueue, QueryType } = require('discord-player'); +const { lyricsExtractor } = require('@discord-player/extractor'); + +module.exports = { + isNew: true, + isBeta: false, + data: new SlashCommandBuilder() + .setName('lyrics') + .setDescription('Get lyrics from Genius for current or specified track.') + .setDMPermission(false) + .setNSFW(false) + .addStringOption((option) => + option + .setName('query') + .setDescription('Search query or URL.') + .setRequired(false) + .setMinLength(2) + .setMaxLength(500) + .setAutocomplete(true) + ), + autocomplete: async ({ interaction }) => { + const query = interaction.options.getString('query', true); + if (query.length < 2) { + return; + } + const genius = lyricsExtractor(); + const lyricsResult = await genius.search(query).catch(() => null); + + let response = []; + + if (!lyricsResult) { + const player = useMainPlayer(); + const searchResults = await player.search(query); + response = searchResults.tracks.slice(0, 1).map((track) => ({ + name: + `${track.title} [Artist: ${track.author}]`.length > 100 + ? `${track.title}`.slice(0, 100) + : `${track.title} [Author: ${track.author}]`, + value: track.title + })); + } else { + response = [ + { + name: `${lyricsResult.title} [Artist: ${lyricsResult.artist.name}]`, + value: lyricsResult.title + } + ]; + } + + if (!response || response.length === 0) { + return interaction.respond([]); + } + + logger.debug(`[Shard ${interaction.guild.shardId}] Autocomplete search responded for query: ${query}`); + return interaction.respond(response); + }, + execute: async ({ interaction }) => { + const query = interaction.options.getString('query'); + const queue = useQueue(interaction.guild.id); + let geniusSearchQuery = ''; + + if (!query) { + if (await notInVoiceChannel(interaction)) { + return; + } + + if (await queueDoesNotExist(interaction, queue)) { + return; + } + + if (await notInSameVoiceChannel(interaction, queue)) { + return; + } + + if (await queueNoCurrentTrack(interaction, queue)) { + return; + } + geniusSearchQuery = queue.currentTrack.title.slice(0, 50); + } + + let searchResult; + if (query) { + const player = useMainPlayer(); + const searchResults = await player.search(query, { + searchEngine: QueryType.SPOTIFY_SEARCH + }); + + if (searchResults.tracks.length === 0) { + logger.debug( + `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no search results found.` + ); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.warning} No search results found**\nThere was no search results found for query **${query}**.` + ) + .setColor(embedOptions.colors.warning) + ] + }); + } + + searchResult = searchResults.tracks[0]; + geniusSearchQuery = searchResults.tracks[0].title; + logger.debug(`Using query for genius: ${geniusSearchQuery}`); + } + + // get lyrics + const genius = lyricsExtractor(); + let lyricsResult = await genius.search(geniusSearchQuery).catch(() => null); + + // try again with shorter query (some titles just have added info in the end) + if (!lyricsResult && geniusSearchQuery.length > 20) { + lyricsResult = await genius.search(geniusSearchQuery.slice(0, 20)).catch(() => null); + } + if (!lyricsResult && geniusSearchQuery.length > 10) { + lyricsResult = await genius.search(geniusSearchQuery.slice(0, 10)).catch(() => null); + } + + // Check if authors in track from searchResult includes the artist name from genius + if (searchResult && lyricsResult) { + const searchResultAuthorIncludesArtist = searchResult.author + .toLowerCase() + .includes(lyricsResult.artist.name.toLowerCase()); + const lyricsResultArtistIncludesAuthor = lyricsResult.artist.name + .toLowerCase() + .includes(searchResult.author.toLowerCase()); + const searchResultAuthorSplitIncludesArtist = lyricsResult.artist.name + .toLowerCase() + .includes(searchResult.author.split(', ')[0].toLowerCase()); + + if ( + !searchResultAuthorIncludesArtist && + !lyricsResultArtistIncludesAuthor && + !searchResultAuthorSplitIncludesArtist + ) { + lyricsResult = null; + logger.debug('Found lyrics but artist name did not match from player result.'); + } + } + + if (!lyricsResult || !lyricsResult.lyrics) { + logger.debug( + `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no lyrics found.` + ); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.warning} No lyrics found**\nThere was no Genius lyrics found for track **${geniusSearchQuery}**.` + ) + .setColor(embedOptions.colors.warning) + ] + }); + } + + // If message length is too long, split into multiple messages + if (lyricsResult.lyrics.length > 3800) { + const messageCount = Math.ceil(lyricsResult.lyrics.length / 3800); + for (let i = 0; i < messageCount; i++) { + const message = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800); + if (i === 0) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.queue} Showing lyrics**\n` + + `**Track: [${lyricsResult.title}](${lyricsResult.url})**\n` + + `**Artist: [${lyricsResult.artist.name}](${lyricsResult.artist.url})**` + + `\n\n\`\`\`fix\n${message}\`\`\`` + ) + .setColor(embedOptions.colors.info) + ] + }); + continue; + } else { + await interaction.channel.send({ + embeds: [ + new EmbedBuilder() + .setDescription(`\`\`\`fix\n${message}\`\`\``) + .setColor(embedOptions.colors.info) + ] + }); + } + } + + return; + } + + logger.debug( + `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and retrieved lyrics.` + ); + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.queue} Showing lyrics**\n` + + `**Track: [${lyricsResult.title}](${lyricsResult.url})**\n` + + `**Artist: [${lyricsResult.artist.name}](${lyricsResult.artist.url})**` + + `\n\n\`\`\`fix\n${lyricsResult.lyrics.slice(0, 3096)}\`\`\`` + ) + .setColor(embedOptions.colors.info) + ] + }); + } +};