Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Lyrics.js #221

Merged
merged 6 commits into from
Nov 12, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/commands/music/Lyrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { ApplicationCommandOptionType } = require('discord.js');
const Command = require('../../structures/Command');
const lyricsFinder = require('lyrics-finder');
const _ = require('lodash');
const { EmbedBuilder } = require('discord.js');

module.exports = class Lyrics extends Command {
constructor(client) {
super(client, {
name: 'lyrics',
description: {
content: 'Search lyrics of the song.',
usage: '<query>',
},
args: false,
voiceRequirements: {
isInVoiceChannel: false,
isInSameVoiceChannel: false,
isPlaying: false,
},
options: [{
name: 'song',
type: ApplicationCommandOptionType.String,
required: false,
description: 'Enter song name or current song playing.',
}],
slashCommand: true,
});
}
async run(client, ctx, args) {
const player = client.music.players.get(ctx.guild.id);
let SongTitle = args.join(' ');
if (!args[0] && !player || !player.queue.current) return ctx.sendMessage('❌ | Nothing is playing right now...');
if (!args[0]) SongTitle = player.queue.current.title;
const FindSongTitle = SongTitle.replace(
/lyrics|lyric|lyrical|official music video|\(official music video\)|\(Official Video\)|audio|\(audio\)|official|official video|official video hd|official hd video|offical video music|\(offical video music\)|extended|hd|(\[.+\])/gi,
'',
);

let lyrics = await lyricsFinder(FindSongTitle);
const pages = [];
if (!lyrics)
return ctx.sendMessage(`**No lyrics found for -** \`${SongTitle}\``);
lyrics = lyrics.split('\n'); // spliting into lines
const SplitedLyrics = _.chunk(lyrics, 40); // 45 lines each page

SplitedLyrics.map((ly) => {
let pagesNum = SplitedLyrics.length;
if (pagesNum === 0) pagesNum = 1;
for (let i = 0; i <= pagesNum; i++) {
const em = new EmbedBuilder()
.setAuthor({
name: `Lyrics for: ${SongTitle}`,
iconURL: client.user.displayAvatarURL(),
})
.setColor('#292B2F')
.setDescription(ly.join('\n'));

if (args.join(' ') !== SongTitle)
em.setThumbnail(player.queue.current.thumbnail);
pages.push(em);

}
});


return ctx.messageHelper.paginate(pages);

}
};