From 317cbf6265f8f2c72d80520996bbca5c948e93ad Mon Sep 17 00:00:00 2001 From: BrunoSobrino <90165013+BrunoSobrino@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:23:34 -0600 Subject: [PATCH] Update buscador-lyrics.js --- plugins/buscador-lyrics.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/buscador-lyrics.js b/plugins/buscador-lyrics.js index 4e67a9057d..bd26cd0fc1 100644 --- a/plugins/buscador-lyrics.js +++ b/plugins/buscador-lyrics.js @@ -14,7 +14,12 @@ const handler = async (m, { conn, text, usedPrefix, command }) => { if (!teks) throw `*${tradutor.texto1} ${usedPrefix + command} beret ojala*`; try { const result = await getTracks(teks); - let lyrics = await searchLyrics(`${result[0].artist} ${result[0].title}`); + let lyrics; + if (result) { + lyrics = await searchLyrics(`${result[0]?.artist} ${result[0]?.title}`); + } else { + lyrics = await searchLyrics(`teks`); + } const res = await fetch(global.API('https://some-random-api.com', '/lyrics', { title: result[0].artist + result[0].title })); const json = await res.json(); let img; @@ -28,9 +33,11 @@ const handler = async (m, { conn, text, usedPrefix, command }) => { img = await bochil.getRandom(); } } - const textoLetra = `${tradutor.texto2[0]} *${result[0].title || ''}*\n${tradutor.texto2[1]} *${result[0].artist || ''}*\n\n${tradutor.texto2[2]} \n${lyrics.lyrics || ''}`; + const tituloL = result[0].title ? result[0].title : lyrics.title + const artistaL = result[0].artist ? result[0].artist : lyrics.artist + const textoLetra = `${tradutor.texto2[0]} *${tituloL || ''}*\n${tradutor.texto2[1]} *${artistaL || ''}*\n\n${tradutor.texto2[2]} \n${lyrics.lyrics || ''}`; await conn.sendMessage(m.chat, { image: { url: img }, caption: textoLetra }, { quoted: m }); - await conn.sendMessage(m.chat, { audio: { url: result[0].preview }, fileName: `${result[0].artist} ${result[0].title}.mp3`, mimetype: 'audio/mp4' }, { quoted: m }); + await conn.sendMessage(m.chat, { audio: { url: result[0]?.preview }, fileName: `${artistaL || '-'} - ${tituloL || '-'}.mp3`, mimetype: 'audio/mp4' }, { quoted: m }); } catch { throw `*${tradutor.texto2[3]}*`; }