Fix 'Unexpected Token {': JavaScript Error in YouTube Downloader Code
There are a couple of errors in your code. Here's the corrected code:
import yts from 'yt-search'
import ytdl from 'ytdl-core'
import { apivisit } from './kanghit.js'
let handler = async (m, { conn, text }) => {
if (!text) throw 'Input Query'
let vid = await yts(ytdl.validateURL(text) ? { videoId: await ytdl.getURLVideoID(text) } : { query: text })
vid = vid.videos ? vid.videos[0] : vid
if (!vid) throw 'Video/Audio Tidak Ditemukan'
let { title, description, url, seconds, timestamp, views, ago, image } = vid
let capt = `*Title:* ${title}
*Published:* ${ago}
*Views:* ${views}
*Description:* ${description}
*Url:* ${url}`
try {
let aud = await conn.sendMessage(m.chat, { [seconds > 1900 ? 'document' : 'audio']: { url: `https://pnggilajacn.my.id/api/download/ytmp3?url=${url}` }, mimetype: 'audio/mpeg', fileName: `${title}.mp3` }, { quoted: m })
conn.sendMessage(m.chat, { text: capt }, { quoted: aud })
await apivisit()
} catch (e) {
console.log(e)
m.reply(`Terjadi kesalahan.`)
}
}
handler.help = handler.alias = ['play'].map(v => v + ' <query>')
handler.tags = ['downloader']
handler.command = /^(play)$/i
export default handler
I have fixed the error in this line:
let aud = await conn.sendMessage(m.chat, { [seconds > 1900 ? 'document' : 'audio']: { url: `https://pnggilajacn.my.id/api/download/ytmp3?url=`+url` }, mimetype: 'audio/mpeg', fileName: `${title}.mp3` }, { quoted: m })
The issue was with the concatenation of the URL. I replaced the backticks (`) with a plus sign (+) to concatenate the URL properly.
I also added parentheses after apivisit to call the function apivisit.
Please try running the code again, and it should work without any syntax errors.
原文地址: https://www.cveoy.top/t/topic/qnqL 著作权归作者所有。请勿转载和采集!