45 lines
1.6 KiB
JavaScript
Executable File
45 lines
1.6 KiB
JavaScript
Executable File
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js')
|
|
const { useQueue } = require('discord-player')
|
|
const { lyricsExtractor } = require('@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) {
|
|
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] })
|
|
}
|
|
} |