Skip to content

Commit

Permalink
Create Lyrics.ts
Browse files Browse the repository at this point in the history
Addidng lyrics command using genius api key

Signed-off-by: Charles Giann Marcelo / Naig <[email protected]>
  • Loading branch information
CharlesNaig authored Sep 7, 2024
1 parent 356aff9 commit 6c70ca6
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/commands/music/Lyrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import { getLyrics } from 'genius-lyrics-api';

export default class Lyrics extends Command {
constructor(client: Lavamusic) {
super(client, {
name: "lyrics",
description: {
content: "cmd.lyrics.description",
examples: ["lyrics"],
usage: "lyrics",
},
category: "music",
aliases: ["ly"],
cooldown: 3,
args: false,
vote: false,
player: {
voice: true,
dj: false,
active: true,
djPerm: null,
},
permissions: {
dev: false,
client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"],
user: [],
},
slashCommand: true,
options: [],
});
}

public async run(client: Lavamusic, ctx: Context): Promise<any> {
const player = client.queue.get(ctx.guild!.id);
const embed = this.client.embed();

if (!player || !player.isPlaying) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_playing"))],
});
}

const currentTrack = player.current;
const trackTitle = currentTrack.info.title;
const artistName = currentTrack.info.author;
const trackUrl = currentTrack.info.uri
const artworkUrl = currentTrack.info.artworkUrl;

const options = {
apiKey: this.client.config.lyricsApi,
title: trackTitle,
artist: artistName,
optimizeQuery: true
};

try {
const lyrics = await getLyrics(options);
if (lyrics) {
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.lyrics.lyrics_track", { trackTitle, trackUrl, lyrics})).setThumbnail(artworkUrl).setTimestamp()],
});
} else {
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.no_results"))],
});
}
} catch (error) {
console.error(error);
await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.lyrics.errors.lyrics_error"))],
});
}
}
}

0 comments on commit 6c70ca6

Please sign in to comment.