| 5 | description: 'Get lyrics of a song along with artist and image', |
| 6 | usage: '.lyrics <song name>', |
| 7 | async handler(sock, message, args, context) { |
| 8 | const chatId = context.chatId || message.key.remoteJid; |
| 9 | const songTitle = args.join(' ').trim(); |
| 10 | if (!songTitle) { |
| 11 | await sock.sendMessage(chatId, { |
| 12 | text: '*Please enter the song name to get the lyrics!*\nUsage: `.lyrics <song name>`', |
| 13 | quoted: message |
| 14 | }); |
| 15 | return; |
| 16 | } |
| 17 | try { |
| 18 | const apiUrl = `https://discardapi.dpdns.org/api/music/lyrics?apikey=qasim&song=${encodeURIComponent(songTitle)}`; |
| 19 | const res = await fetch(apiUrl); |
| 20 | if (!res.ok) |
| 21 | throw new Error(`API request failed with status ${res.status}`); |
| 22 | const data = await res.json(); |
| 23 | const messageData = data?.result?.message; |
| 24 | if (!messageData?.lyrics) { |
| 25 | await sock.sendMessage(chatId, { |
| 26 | text: `❌ Sorry, I couldn't find any lyrics for "${songTitle}".`, |
| 27 | quoted: message |
| 28 | }); |
| 29 | return; |
| 30 | } |
| 31 | const { artist, lyrics, image, title, url } = messageData; |
| 32 | const maxChars = 4096; |
| 33 | const lyricsOutput = lyrics.length > maxChars ? `${lyrics.slice(0, maxChars - 3) }...` : lyrics; |
| 34 | const caption = ` |
| 35 | 🎵 *${title}* |
| 36 | 👤 *Artist:* ${artist} |
| 37 | 🔗 *URL:* ${url} |
| 38 | |
| 39 | 📝 *Lyrics:* |
| 40 | ${lyricsOutput} |
| 41 | `.trim(); |
| 42 | if (image) { |
| 43 | await sock.sendMessage(chatId, { |
| 44 | image: { url: image }, |
| 45 | caption, |
| 46 | quoted: message |
| 47 | }); |
| 48 | } |
| 49 | else { |
| 50 | await sock.sendMessage(chatId, { |
| 51 | text: caption, |
| 52 | quoted: message |
| 53 | }); |
| 54 | } |
| 55 | } |
| 56 | catch (error) { |
| 57 | console.error('Lyrics Command Error:', error); |
| 58 | await sock.sendMessage(chatId, { |
| 59 | text: `❌ An error occurred while fetching the lyrics for "${songTitle}".`, |
| 60 | quoted: message |
| 61 | }); |
| 62 | } |
| 63 | } |
| 64 | }; |