edit instead of posting a new message (fix #145)
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 21s

This commit is contained in:
Mylloon 2024-10-31 20:34:44 +01:00
parent 75ec77a880
commit 2fc39560f0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 20 additions and 8 deletions

View file

@ -1,8 +1,9 @@
import { SlashCommandBuilder } from "@discordjs/builders"; import { SlashCommandBuilder } from "@discordjs/builders";
import { useMainPlayer, useQueue } from "discord-player"; import { useMainPlayer, useQueue } from "discord-player";
import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; import { ChatInputCommandInteraction, Client, EmbedBuilder, Message } from "discord.js";
import { getLocale, getLocalizations } from "../../utils/locales"; import { getLocale, getLocalizations } from "../../utils/locales";
import { getFilename } from "../../utils/misc"; import { getFilename } from "../../utils/misc";
import { discord_limit_message } from "../../utils/constants";
export default { export default {
scope: () => [], scope: () => [],
@ -125,16 +126,23 @@ export default {
// Load lyrics // Load lyrics
const syncedLyrics = queue.syncedLyrics(data[0]); const syncedLyrics = queue.syncedLyrics(data[0]);
let message: Message<boolean>;
syncedLyrics?.onChange(async (lyrics) => { syncedLyrics?.onChange(async (lyrics) => {
const content = `[${data[0].trackName}]: ${lyrics}`;
if (interaction.channel?.isSendable()) { if (interaction.channel?.isSendable()) {
await interaction.channel?.send({ if (message) {
content, const payload = message.cleanContent + "\n" + lyrics;
}); if (payload.length < discord_limit_message) {
message.edit(payload);
return;
}
}
message = await interaction.channel?.send(
(message ? loc.get("c_lyrics6") + " " : "") +
`${data[0].artistName} : **${data[0].trackName}**\n\n` +
lyrics,
);
} else { } else {
await interaction.followUp({ await interaction.followUp(loc.get("c_lyrics5"));
content,
});
} }
}); });

View file

@ -154,6 +154,8 @@
"c_lyrics2": "Unable to find the lyrics for", "c_lyrics2": "Unable to find the lyrics for",
"c_lyrics3": "Unable to find synchronized lyrics for", "c_lyrics3": "Unable to find synchronized lyrics for",
"c_lyrics4": "It's karaoke time!", "c_lyrics4": "It's karaoke time!",
"c_lyrics5": "Unable to post the lyrics here.",
"c_lyrics6": "More of :",
"c_repeat_name": "repeat", "c_repeat_name": "repeat",
"c_repeat_desc": "Command for the type of music repetition", "c_repeat_desc": "Command for the type of music repetition",

View file

@ -154,6 +154,8 @@
"c_lyrics2": "Impossible de trouver les paroles pour", "c_lyrics2": "Impossible de trouver les paroles pour",
"c_lyrics3": "Impossible de trouver les paroles synchronisées pour", "c_lyrics3": "Impossible de trouver les paroles synchronisées pour",
"c_lyrics4": "C'est parti !", "c_lyrics4": "C'est parti !",
"c_lyrics5": "Impossible de poster les paroles ici.",
"c_lyrics6": "Suite de :",
"c_repeat_name": "repeat", "c_repeat_name": "repeat",
"c_repeat_desc": "Commande relative à la répétition des musiques", "c_repeat_desc": "Commande relative à la répétition des musiques",