Skip to content

Commit

Permalink
[Enhancement] Replaced discords player lyrics extractor with the Geni…
Browse files Browse the repository at this point in the history
…us API, api calls are now much faster
  • Loading branch information
naseif committed Oct 18, 2021
1 parent 4e2f586 commit d304257
Show file tree
Hide file tree
Showing 4 changed files with 1,305 additions and 12 deletions.
30 changes: 24 additions & 6 deletions commands/Music/lyrics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const { Lyrics } = require("@discord-player/extractor");
const lyricsClient = Lyrics.init();
const { getLyrics, getSong } = require("genius-lyrics-api");
const { geniusApiKey } = require("../../config.json");

module.exports = {
name: "lyrics",
Expand All @@ -10,6 +10,16 @@ module.exports = {
description: "Gets the lyrics of the current song or a song you pass",
usage: "ly || lyrics <optional song name>",
async run(message, args, client) {
if (!geniusApiKey)
return await message.channel.send({
embeds: [
embedMessage(
"#9dcc37",
"You did not add your Genius API token in the config file!"
),
],
});

const queue = client.player.getQueue(message.guild);
const songString = args.join(" ");
let songTitle;
Expand All @@ -22,7 +32,7 @@ module.exports = {
embeds: [
embedMessage(
"#9dcc37",
"❌ There is no music playing to search for lyrics!"
"❌ There is no music playing to search for lyrics!, Give me the song name instead."
),
],
});
Expand All @@ -38,7 +48,14 @@ module.exports = {
}

try {
const lyrics = await lyricsClient.search(songTitle);
const lyricsOptions = {
apiKey: geniusApiKey,
title: songTitle,
artist: " ",
optimizeQuery: true,
};

const lyrics = await getSong(lyricsOptions);
if (!lyrics)
return await message.channel.send({
embeds: [
Expand All @@ -51,14 +68,14 @@ module.exports = {

const lyricsEmbed = {
color: "#9dcc37",
title: `${lyrics.artist.name} - ${lyrics.title}`,
title: `${lyrics.title}`,
author: {
name: `${message.member.user.username}`,
icon_url: `${message.member.user.avatarURL()}`,
},
description: `${lyrics.lyrics}`,
thumbnail: {
url: `${lyrics.thumbnail}`,
url: `${lyrics.albumArt}`,
},

timestamp: new Date(),
Expand All @@ -77,6 +94,7 @@ module.exports = {
],
});
client.logger(error.message, "error");
console.log(error);
}
},
data: new SlashCommandBuilder()
Expand Down
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"token": "",
"prefix": "",
"mongourl": ""
"mongourl": "",
"geniusApiKey": ""
}
Loading

0 comments on commit d304257

Please sign in to comment.