mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2025-09-21 06:41:35 +01:00
add lyrics command
This commit is contained in:
parent
6f25c45e5f
commit
130ab40eeb
3 changed files with 71 additions and 1 deletions
69
commands/music/lyrics.js
Normal file
69
commands/music/lyrics.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||||
|
const { Genius } = require("genius-lyrics");
|
||||||
|
|
||||||
|
const geniusClient = new Genius.Client(process.env.GENIUS_API_TOKEN);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("lyrics")
|
||||||
|
.setDescription("Get lyrics for the current song or a specific song")
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("song")
|
||||||
|
.setDescription("Song name to search lyrics for (optional)")
|
||||||
|
.setRequired(false)
|
||||||
|
),
|
||||||
|
async execute(interaction, client) {
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
let songQuery = interaction.options.getString("song");
|
||||||
|
const queue = client.distube.getQueue(interaction.guildId);
|
||||||
|
|
||||||
|
if (!songQuery && queue && queue.songs.length > 0) {
|
||||||
|
songQuery = queue.songs[0].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!songQuery) {
|
||||||
|
return interaction.followUp(
|
||||||
|
"❌ Please specify a song name or play a song first!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const searches = await geniusClient.songs.search(songQuery);
|
||||||
|
if (searches.length === 0) {
|
||||||
|
return interaction.followUp("❌ No lyrics found for this song!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const song = searches[0];
|
||||||
|
const lyrics = await song.lyrics();
|
||||||
|
|
||||||
|
if (lyrics.length > 4096) {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor("#FF0000")
|
||||||
|
.setTitle(`Lyrics for: ${song.title}`)
|
||||||
|
.setDescription(
|
||||||
|
`The lyrics are too long to display in Discord. [View on Genius](${song.url})`
|
||||||
|
)
|
||||||
|
.setThumbnail(song.thumbnail)
|
||||||
|
.setFooter({ text: "Powered by Genius API" });
|
||||||
|
|
||||||
|
return interaction.followUp({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor("#0099ff")
|
||||||
|
.setTitle(`Lyrics for: ${song.title}`)
|
||||||
|
.setDescription(lyrics)
|
||||||
|
.setThumbnail(song.thumbnail)
|
||||||
|
.setFooter({ text: "Powered by Genius API" });
|
||||||
|
|
||||||
|
interaction.followUp({ embeds: [embed] });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching lyrics:", error);
|
||||||
|
interaction.followUp(
|
||||||
|
"❌ Failed to fetch lyrics. Please try again later."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
2
index.js
2
index.js
|
@ -48,7 +48,7 @@ client.distube
|
||||||
})
|
})
|
||||||
.on("error", (channel, error) => {
|
.on("error", (channel, error) => {
|
||||||
console.error("DisTube error:", error);
|
console.error("DisTube error:", error);
|
||||||
channel.send("❌ An error occurred: " + error.message);
|
queue.textChannel.send("❌ An error occurred: " + error.message);
|
||||||
})
|
})
|
||||||
.on("finish", (queue) => {
|
.on("finish", (queue) => {
|
||||||
queue.textChannel.send("🎵 Queue finished!");
|
queue.textChannel.send("🎵 Queue finished!");
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
"distube": "^5.0.7",
|
"distube": "^5.0.7",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
"genius-lyrics": "^4.4.7",
|
||||||
"html-entities": "^2.5.2",
|
"html-entities": "^2.5.2",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"mongoose": "^8.6.0",
|
"mongoose": "^8.6.0",
|
||||||
|
|
Loading…
Reference in a new issue