From 006240367dcf25a396efe9ea0e1ab6d89f3679ca Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 18:02:01 +0800 Subject: [PATCH 01/11] Update package.json Module Genius Api Added Signed-off-by: Charles Giann Marcelo / Naig --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 784554098..bed452de1 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,8 @@ "signale": "^1.4.0", "topgg-autoposter": "^2.0.2", "tslib": "^2.7.0", - "undici": "^6.19.8" + "undici": "^6.19.8", + "genius-lyrics-api": "^3.2.1" }, "signale": { "displayScope": true, From 114bfafee43f59907f7ccad2eb712ecdb9143c24 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 18:04:29 +0800 Subject: [PATCH 02/11] Update .env.example Adding api token for privacy Signed-off-by: Charles Giann Marcelo / Naig --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 23e3a6021..307dd77ef 100644 --- a/.env.example +++ b/.env.example @@ -16,9 +16,10 @@ AUTO_NODE=" false" # true for auto node. It is given from lavainfo-api (https:// SEARCH_ENGINE= "YouTubeMusic" # Search engine to be used when playing the song. You can use: YouTube, YouTubeMusic, SoundCloud, Spotify, Apple, Deezer, Yandex and JioSaavn MAX_PLAYLIST_SIZE= "100" # Max playlist size. MAX_QUEUE_SIZE= "100" # Max queue size. +GENIUS_API= "" # Sign up and get your own api at (https://genius.com/) to fetch your lyrics (CLIENT TOKEN) # Configuration for multiple Lavalink servers LAVALINK_SERVERS = '[ {"url":"localhost:2333","auth":"youshallnotpass","name":"Local Node","secure":false}, {"url":"localhost:2333","auth":"youshallnotpass2","name":"Another Node","secure":false} -]' \ No newline at end of file +]' From e5a7a2554d1630c58bd32b09fb74fd518d812a10 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 18:05:47 +0800 Subject: [PATCH 03/11] Update config.ts Genius Api Signed-off-by: Charles Giann Marcelo / Naig --- src/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.ts b/src/config.ts index 34257ddd3..61da8f1db 100644 --- a/src/config.ts +++ b/src/config.ts @@ -55,6 +55,7 @@ export default { guildId: process.env.GUILD_ID, logChannelId: process.env.LOG_CHANNEL_ID, commandLogs: process.env.LOG_COMMANDS_ID, + lyricsApi: process.env.GENIUS_API, links: { img: process.env.IMG_LINK || "https://i.imgur.com/ud3EWNh.jpg", }, From 356aff9271d6b97f0ed1a0ba1c3ac12d2b1023c9 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 18:25:28 +0800 Subject: [PATCH 04/11] Update EnglishUS.json Signed-off-by: Charles Giann Marcelo / Naig --- locales/EnglishUS.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/locales/EnglishUS.json b/locales/EnglishUS.json index 67c09d3b6..6a376d64e 100644 --- a/locales/EnglishUS.json +++ b/locales/EnglishUS.json @@ -263,6 +263,15 @@ "looping_queue": "**Looping the queue.**", "looping_off": "**Looping is now off.**" }, + "lyrics": { + "description": "Get's the lyrics of the currently playing track.", + "lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n`${lyrics}`", + "errors": { + "no_results": "No lyrics found for the current track.", + "no_playing": "No track is currently playing.", + "lyrics_error": "An error occurred while getting the lyrics." + } + }, "nowplaying": { "description": "Shows the currently playing song", "now_playing": "Now Playing", @@ -629,4 +638,4 @@ "Leave a guild": "Leave a guild", "List all guilds the bot is in": "List all guilds the bot is in", "Restart the bot": "Restart the bot" -} \ No newline at end of file +} From 6c70ca68f13c35d544bb3478e01c2355c973fdc2 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 18:26:40 +0800 Subject: [PATCH 05/11] Create Lyrics.ts Addidng lyrics command using genius api key Signed-off-by: Charles Giann Marcelo / Naig --- src/commands/music/Lyrics.ts | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/commands/music/Lyrics.ts diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts new file mode 100644 index 000000000..d638d0f7f --- /dev/null +++ b/src/commands/music/Lyrics.ts @@ -0,0 +1,75 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import { getLyrics } from 'genius-lyrics-api'; + +export default class Lyrics extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "lyrics", + description: { + content: "cmd.lyrics.description", + examples: ["lyrics"], + usage: "lyrics", + }, + category: "music", + aliases: ["ly"], + cooldown: 3, + args: false, + vote: false, + player: { + voice: true, + dj: false, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [], + }); + } + + public async run(client: Lavamusic, ctx: Context): Promise { + const player = client.queue.get(ctx.guild!.id); + const embed = this.client.embed(); + + if (!player || !player.isPlaying) { + return await ctx.sendMessage({ + embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))], + }); + } + + const currentTrack = player.current; + const trackTitle = currentTrack.info.title; + const artistName = currentTrack.info.author; + const trackUrl = currentTrack.info.uri + const artworkUrl = currentTrack.info.artworkUrl; + + const options = { + apiKey: this.client.config.lyricsApi, + title: trackTitle, + artist: artistName, + optimizeQuery: true + }; + + try { + const lyrics = await getLyrics(options); + if (lyrics) { + await ctx.sendMessage({ + embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics})).setThumbnail(artworkUrl).setTimestamp()], + }); + } else { + await ctx.sendMessage({ + embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))], + }); + } + } catch (error) { + console.error(error); + await ctx.sendMessage({ + embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))], + }); + } + } +} From 9c1d2f25fb6c172bb8959d7d974be6857af10922 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sat, 7 Sep 2024 23:35:09 +0800 Subject: [PATCH 06/11] Update Lyrics.ts Signed-off-by: Charles Giann Marcelo / Naig --- src/commands/music/Lyrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts index d638d0f7f..35bb34043 100644 --- a/src/commands/music/Lyrics.ts +++ b/src/commands/music/Lyrics.ts @@ -35,7 +35,7 @@ export default class Lyrics extends Command { const player = client.queue.get(ctx.guild!.id); const embed = this.client.embed(); - if (!player || !player.isPlaying) { + if (!player && !player.isPlaying) { return await ctx.sendMessage({ embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))], }); From 6abf5218699492cb3660e0817b2bc9f5fe671b97 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sun, 8 Sep 2024 05:34:47 +0800 Subject: [PATCH 07/11] Update Lyrics.ts Updated with pages buttons Signed-off-by: Charles Giann Marcelo / Naig --- src/commands/music/Lyrics.ts | 103 +++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts index 35bb34043..17ad498ce 100644 --- a/src/commands/music/Lyrics.ts +++ b/src/commands/music/Lyrics.ts @@ -1,5 +1,6 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; import { getLyrics } from 'genius-lyrics-api'; +import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from 'discord.js'; export default class Lyrics extends Command { constructor(client: Lavamusic) { @@ -33,22 +34,22 @@ export default class Lyrics extends Command { public async run(client: Lavamusic, ctx: Context): Promise { const player = client.queue.get(ctx.guild!.id); - const embed = this.client.embed(); + const embed = new EmbedBuilder(); - if (!player && !player.isPlaying) { + if (!player || !player.isPlaying) { return await ctx.sendMessage({ - embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))], + embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))], }); } const currentTrack = player.current; - const trackTitle = currentTrack.info.title; - const artistName = currentTrack.info.author; - const trackUrl = currentTrack.info.uri + const trackTitle = currentTrack.info.title.replace(/\[.*?\]/g, '').trim(); + const artistName = currentTrack.info.author.replace(/\[.*?\]/g, '').trim(); + const trackUrl = currentTrack.info.uri; const artworkUrl = currentTrack.info.artworkUrl; const options = { - apiKey: this.client.config.lyricsApi, + apiKey: client.config.lyricsApi, title: trackTitle, artist: artistName, optimizeQuery: true @@ -57,19 +58,99 @@ export default class Lyrics extends Command { try { const lyrics = await getLyrics(options); if (lyrics) { - await ctx.sendMessage({ - embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics})).setThumbnail(artworkUrl).setTimestamp()], + const lyricsPages = this.paginateLyrics(lyrics); + let currentPage = 0; + + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('prev') + .setEmoji(this.client.emoji.page.back) + .setStyle(ButtonStyle.Secondary) + .setDisabled(true), + new ButtonBuilder() + .setCustomId('stop') + .setEmoji(this.client.emoji.page.cancel) + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId('next') + .setEmoji(this.client.emoji.page.next) + .setStyle(ButtonStyle.Secondary) + .setDisabled(lyricsPages.length <= 1) + ); + + const message = await ctx.sendMessage({ + embeds: [embed.setColor(client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] })).setThumbnail(artworkUrl).setTimestamp()], + components: [row] + }); + + const filter = (interaction) => interaction.user.id === ctx.author.id; + const collector = message.createMessageComponentCollector({ filter, componentType: ComponentType.Button, time: 60000 }); + + collector.on('collect', async (interaction) => { + if (interaction.customId === 'prev') { + currentPage--; + } else if (interaction.customId === 'next') { + currentPage++; + } else if (interaction.customId === 'stop') { + collector.stop(); + return interaction.update({ components: [] }); + } + + await interaction.update({ + embeds: [embed.setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] })).setThumbnail(artworkUrl).setTimestamp()], + components: [ + new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('prev') + .setEmoji(this.client.emoji.page.back) + .setStyle(ButtonStyle.Secondary) + .setDisabled(currentPage === 0), + new ButtonBuilder() + .setCustomId('stop') + .setEmoji(this.client.emoji.page.cancel) + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId('next') + .setEmoji(this.client.emoji.page.next) + .setStyle(ButtonStyle.Secondary) + .setDisabled(currentPage === lyricsPages.length - 1) + ) + ] + }); + }); + + collector.on('end', () => { + message.edit({ components: [] }); }); } else { await ctx.sendMessage({ - embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))], + embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))], }); } } catch (error) { console.error(error); await ctx.sendMessage({ - embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))], + embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))], }); } } + + paginateLyrics(lyrics) { + const lines = lyrics.split('\n'); + const pages = []; + let page = ''; + + for (const line of lines) { + if (page.length + line.length > 2048) { + pages.push(page); + page = ''; + } + page += `${line}\n`; + } + + if (page) pages.push(page); + return pages; + } } From e384138196bdad343faaef6ef2b2aff72478541e Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Sun, 8 Sep 2024 05:36:33 +0800 Subject: [PATCH 08/11] Update EnglishUS.json removing ` Signed-off-by: Charles Giann Marcelo / Naig --- locales/EnglishUS.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/EnglishUS.json b/locales/EnglishUS.json index 6a376d64e..e1bf11967 100644 --- a/locales/EnglishUS.json +++ b/locales/EnglishUS.json @@ -265,7 +265,7 @@ }, "lyrics": { "description": "Get's the lyrics of the currently playing track.", - "lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n`${lyrics}`", + "lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n${lyrics}", "errors": { "no_results": "No lyrics found for the current track.", "no_playing": "No track is currently playing.", From 06c8396bea0cb59069b16bed9db9a42b9fea8c91 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Tue, 10 Sep 2024 01:00:07 +0800 Subject: [PATCH 09/11] Update EnglishUS.json Signed-off-by: Charles Giann Marcelo / Naig --- locales/EnglishUS.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/locales/EnglishUS.json b/locales/EnglishUS.json index e1bf11967..1dbd0db8f 100644 --- a/locales/EnglishUS.json +++ b/locales/EnglishUS.json @@ -265,7 +265,8 @@ }, "lyrics": { "description": "Get's the lyrics of the currently playing track.", - "lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n${lyrics}", + "lyrics_track": "### Lyrics for: [{trackTitle}]({trackUrl})\n**`{lyrics}`**", + "searching": "`🔍` Searching for **{trackTitle}** lyrics...", "errors": { "no_results": "No lyrics found for the current track.", "no_playing": "No track is currently playing.", From 110b3eb5e757b43336781160c594e4c765a0b3e8 Mon Sep 17 00:00:00 2001 From: Charles Giann Marcelo / Naig Date: Tue, 10 Sep 2024 01:00:34 +0800 Subject: [PATCH 10/11] Update Lyrics.ts Signed-off-by: Charles Giann Marcelo / Naig --- src/commands/music/Lyrics.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts index 17ad498ce..5dc6324d1 100644 --- a/src/commands/music/Lyrics.ts +++ b/src/commands/music/Lyrics.ts @@ -47,14 +47,17 @@ export default class Lyrics extends Command { const artistName = currentTrack.info.author.replace(/\[.*?\]/g, '').trim(); const trackUrl = currentTrack.info.uri; const artworkUrl = currentTrack.info.artworkUrl; - + + // Send initial "Searching for lyrics" message + const searchMessage = await ctx.sendDeferMessage(ctx.locale("cmd.lyrics.searching", { trackTitle })) + const options = { apiKey: client.config.lyricsApi, title: trackTitle, artist: artistName, optimizeQuery: true }; - + try { const lyrics = await getLyrics(options); if (lyrics) { @@ -79,13 +82,14 @@ export default class Lyrics extends Command { .setDisabled(lyricsPages.length <= 1) ); - const message = await ctx.sendMessage({ + // Edit the initial message to include lyrics + await searchMessage.edit({ embeds: [embed.setColor(client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] })).setThumbnail(artworkUrl).setTimestamp()], components: [row] }); const filter = (interaction) => interaction.user.id === ctx.author.id; - const collector = message.createMessageComponentCollector({ filter, componentType: ComponentType.Button, time: 60000 }); + const collector = searchMessage.createMessageComponentCollector({ filter, componentType: ComponentType.Button, time: 60000 }); collector.on('collect', async (interaction) => { if (interaction.customId === 'prev') { @@ -122,16 +126,16 @@ export default class Lyrics extends Command { }); collector.on('end', () => { - message.edit({ components: [] }); + searchMessage.edit({ components: [] }); }); } else { - await ctx.sendMessage({ + await searchMessage.edit({ embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))], }); } } catch (error) { console.error(error); - await ctx.sendMessage({ + await searchMessage.edit({ embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))], }); } From 054d9322f6a10f304abcddf6a8945fccface1f8f Mon Sep 17 00:00:00 2001 From: LucasB25 <50886682+LucasB25@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:26:26 +0200 Subject: [PATCH 11/11] update --- package.json | 4 +- src/commands/music/Lyrics.ts | 151 +++++++++++++++----------- src/events/client/VoiceStateUpdate.ts | 2 +- src/structures/Context.ts | 2 +- 4 files changed, 91 insertions(+), 68 deletions(-) diff --git a/package.json b/package.json index bed452de1..e51fe0ee8 100644 --- a/package.json +++ b/package.json @@ -46,14 +46,14 @@ "@top-gg/sdk": "^3.1.6", "discord.js": "^14.16.1", "dotenv": "^16.4.5", + "genius-lyrics-api": "^3.2.1", "i18n": "^0.15.1", "node-system-stats": "^1.3.0", "shoukaku": "github:shipgirlproject/Shoukaku#master", "signale": "^1.4.0", "topgg-autoposter": "^2.0.2", "tslib": "^2.7.0", - "undici": "^6.19.8", - "genius-lyrics-api": "^3.2.1" + "undici": "^6.19.8" }, "signale": { "displayScope": true, diff --git a/src/commands/music/Lyrics.ts b/src/commands/music/Lyrics.ts index 5dc6324d1..d24c2dc5e 100644 --- a/src/commands/music/Lyrics.ts +++ b/src/commands/music/Lyrics.ts @@ -1,6 +1,6 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; -import { getLyrics } from 'genius-lyrics-api'; -import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from 'discord.js'; +import { getLyrics } from "genius-lyrics-api"; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from "discord.js"; export default class Lyrics extends Command { constructor(client: Lavamusic) { @@ -34,28 +34,27 @@ export default class Lyrics extends Command { public async run(client: Lavamusic, ctx: Context): Promise { const player = client.queue.get(ctx.guild!.id); - const embed = new EmbedBuilder(); - - if (!player || !player.isPlaying) { + const embed = this.client.embed(); + + if (!(player && !player.isPlaying)) { return await ctx.sendMessage({ embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))], }); } - + const currentTrack = player.current; - const trackTitle = currentTrack.info.title.replace(/\[.*?\]/g, '').trim(); - const artistName = currentTrack.info.author.replace(/\[.*?\]/g, '').trim(); + const trackTitle = currentTrack.info.title.replace(/\[.*?\]/g, "").trim(); + const artistName = currentTrack.info.author.replace(/\[.*?\]/g, "").trim(); const trackUrl = currentTrack.info.uri; const artworkUrl = currentTrack.info.artworkUrl; - // Send initial "Searching for lyrics" message - const searchMessage = await ctx.sendDeferMessage(ctx.locale("cmd.lyrics.searching", { trackTitle })) + await ctx.sendDeferMessage(ctx.locale("cmd.lyrics.searching", { trackTitle })); const options = { apiKey: client.config.lyricsApi, title: trackTitle, artist: artistName, - optimizeQuery: true + optimizeQuery: true, }; try { @@ -64,92 +63,105 @@ export default class Lyrics extends Command { const lyricsPages = this.paginateLyrics(lyrics); let currentPage = 0; - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId('prev') - .setEmoji(this.client.emoji.page.back) - .setStyle(ButtonStyle.Secondary) - .setDisabled(true), - new ButtonBuilder() - .setCustomId('stop') - .setEmoji(this.client.emoji.page.cancel) - .setStyle(ButtonStyle.Danger), - new ButtonBuilder() - .setCustomId('next') - .setEmoji(this.client.emoji.page.next) - .setStyle(ButtonStyle.Secondary) - .setDisabled(lyricsPages.length <= 1) - ); - - // Edit the initial message to include lyrics - await searchMessage.edit({ - embeds: [embed.setColor(client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] })).setThumbnail(artworkUrl).setTimestamp()], - components: [row] + const row = new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("prev") + .setEmoji(this.client.emoji.page.back) + .setStyle(ButtonStyle.Secondary) + .setDisabled(true), + new ButtonBuilder().setCustomId("stop").setEmoji(this.client.emoji.page.cancel).setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId("next") + .setEmoji(this.client.emoji.page.next) + .setStyle(ButtonStyle.Secondary) + .setDisabled(lyricsPages.length <= 1), + ); + + await ctx.editMessage({ + embeds: [ + embed + .setColor(client.color.main) + .setDescription( + ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] }), + ) + .setThumbnail(artworkUrl) + .setTimestamp(), + ], + components: [row], }); const filter = (interaction) => interaction.user.id === ctx.author.id; - const collector = searchMessage.createMessageComponentCollector({ filter, componentType: ComponentType.Button, time: 60000 }); + const collector = ctx.channel.createMessageComponentCollector({ + filter, + componentType: ComponentType.Button, + time: 60000, + }); - collector.on('collect', async (interaction) => { - if (interaction.customId === 'prev') { + collector.on("collect", async (interaction) => { + if (interaction.customId === "prev") { currentPage--; - } else if (interaction.customId === 'next') { + } else if (interaction.customId === "next") { currentPage++; - } else if (interaction.customId === 'stop') { + } else if (interaction.customId === "stop") { collector.stop(); return interaction.update({ components: [] }); } await interaction.update({ - embeds: [embed.setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] })).setThumbnail(artworkUrl).setTimestamp()], - components: [ - new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId('prev') - .setEmoji(this.client.emoji.page.back) - .setStyle(ButtonStyle.Secondary) - .setDisabled(currentPage === 0), - new ButtonBuilder() - .setCustomId('stop') - .setEmoji(this.client.emoji.page.cancel) - .setStyle(ButtonStyle.Danger), - new ButtonBuilder() - .setCustomId('next') - .setEmoji(this.client.emoji.page.next) - .setStyle(ButtonStyle.Secondary) - .setDisabled(currentPage === lyricsPages.length - 1) + embeds: [ + embed + .setDescription( + ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics: lyricsPages[currentPage] }), ) - ] + .setThumbnail(artworkUrl) + .setTimestamp(), + ], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("prev") + .setEmoji(this.client.emoji.page.back) + .setStyle(ButtonStyle.Secondary) + .setDisabled(currentPage === 0), + new ButtonBuilder() + .setCustomId("stop") + .setEmoji(this.client.emoji.page.cancel) + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId("next") + .setEmoji(this.client.emoji.page.next) + .setStyle(ButtonStyle.Secondary) + .setDisabled(currentPage === lyricsPages.length - 1), + ), + ], }); }); - collector.on('end', () => { - searchMessage.edit({ components: [] }); + collector.on("end", () => { + ctx.editMessage({ components: [] }); }); } else { - await searchMessage.edit({ + await ctx.editMessage({ embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))], }); } } catch (error) { console.error(error); - await searchMessage.edit({ + await ctx.editMessage({ embeds: [embed.setColor(client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))], }); } } paginateLyrics(lyrics) { - const lines = lyrics.split('\n'); + const lines = lyrics.split("\n"); const pages = []; - let page = ''; + let page = ""; for (const line of lines) { if (page.length + line.length > 2048) { pages.push(page); - page = ''; + page = ""; } page += `${line}\n`; } @@ -158,3 +170,14 @@ export default class Lyrics extends Command { return pages; } } + +/** + * Project: lavamusic + * Author: Appu + * Main Contributor: LucasB25 + * Company: Coders + * Copyright (c) 2024. All rights reserved. + * This code is the property of Coder and may not be reproduced or + * modified without permission. For more information, contact us at + * https://discord.gg/ns8CTk9J3e + */ diff --git a/src/events/client/VoiceStateUpdate.ts b/src/events/client/VoiceStateUpdate.ts index e057eecb4..80c2029d2 100644 --- a/src/events/client/VoiceStateUpdate.ts +++ b/src/events/client/VoiceStateUpdate.ts @@ -86,4 +86,4 @@ export default class VoiceStateUpdate extends Event { * This code is the property of Coder and may not be reproduced or * modified without permission. For more information, contact us at * https://discord.gg/ns8CTk9J3e - */ \ No newline at end of file + */ diff --git a/src/structures/Context.ts b/src/structures/Context.ts index 074eaa1ee..40b44144f 100644 --- a/src/structures/Context.ts +++ b/src/structures/Context.ts @@ -44,7 +44,7 @@ export default class Context { this.message = ctx instanceof Message ? ctx : null; if (ctx.channel && ctx.channel.type !== ChannelType.GroupDM) { - this.channel = ctx.channel + this.channel = ctx.channel; } else { this.channel = null; }