Réécriture complète en Typescript
This commit is contained in:
45
src/commands/player/lyrics.ts
Executable file
45
src/commands/player/lyrics.ts
Executable file
@@ -0,0 +1,45 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
import { lyricsExtractor } from '@discord-player/extractor'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('lyrics')
|
||||
.setDescription('Rechercher les paroles d\'une musique.')
|
||||
.addStringOption(option => option.setName('recherche').setDescription('Chercher une musique spécifique')),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
|
||||
let query = interaction.options.getString('recherche', false)
|
||||
if (!query) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
let track = queue.currentTrack
|
||||
if (!track) return interaction.followUp({ content: 'Aucune musique en cours, recherche en une plutôt !' })
|
||||
|
||||
if (track.raw.source === 'spotify') query = `${track.author} ${track.title}`
|
||||
else query = track.title
|
||||
}
|
||||
|
||||
let lyricsFinder = lyricsExtractor()
|
||||
|
||||
let lyrics = await lyricsFinder.search(query).catch(() => null)
|
||||
if (!lyrics) return interaction.followUp({ content: 'Pas de paroles trouvées !' })
|
||||
|
||||
let trimmedLyrics = lyrics.lyrics.substring(0, 1997)
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor('#ffc370')
|
||||
.setTitle(lyrics.title)
|
||||
.setURL(lyrics.url)
|
||||
.setThumbnail(lyrics.thumbnail)
|
||||
.setAuthor({
|
||||
name: lyrics.artist.name,
|
||||
iconURL: lyrics.artist.image,
|
||||
url: lyrics.artist.url
|
||||
})
|
||||
.setDescription(trimmedLyrics.length === 1997 ? `${trimmedLyrics}...` : trimmedLyrics)
|
||||
|
||||
return interaction.followUp({ embeds: [embed] })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user