Ajout /lyrics, /papa et /parle + Fix /crack
This commit is contained in:
45
commands/music/lyrics.js
Executable file
45
commands/music/lyrics.js
Executable file
@@ -0,0 +1,45 @@
|
||||
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] })
|
||||
}
|
||||
}
|
||||
@@ -60,10 +60,10 @@ module.exports = {
|
||||
})
|
||||
}
|
||||
try { if (!queue.connection) await queue.connect(voiceChannel) }
|
||||
catch (error) { console.error(error); return await interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
catch (error) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
|
||||
let result = await player.search(query, { requestedBy: interaction.user })
|
||||
if (!result.hasTracks()) return await interaction.followUp(`Aucune musique trouvée pour **${query}** !`)
|
||||
if (!result.hasTracks()) return interaction.followUp(`Aucune musique trouvée pour **${query}** !`)
|
||||
let track = result.tracks[0]
|
||||
|
||||
let entry = queue.tasksQueue.acquire()
|
||||
@@ -73,14 +73,12 @@ module.exports = {
|
||||
// Write the values in the .env file to recover the player if the bot restarts
|
||||
writeEnv('DISCORD_MUSIC_TEXTCHANNEL_ID', interaction.channel.id)
|
||||
writeEnv('DISCORD_MUSIC_VOICECHANNEL_ID', voiceChannel.id)
|
||||
writeEnv('DISCORD_MUSIC_CURRENT_TRACK', track.url)
|
||||
writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', 0)
|
||||
|
||||
try {
|
||||
if (!queue.isPlaying()) await queue.node.play()
|
||||
track.source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu'
|
||||
return await interaction.followUp(`Chargement de la musique **${track.title}** de **${track.author}** sur **${track.source}**...`)
|
||||
} catch (error) { console.error(error); return await interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
let track_source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu'
|
||||
return interaction.followUp(`Chargement de la musique **${track.title}** de **${track.author}** sur **${track_source}**...`)
|
||||
} catch (error) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
finally { queue.tasksQueue.release() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user