You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ytdl-core更新后出现SyntaxError报错,寻求技术解决

问题描述

更新ytdl-core模块前,用于Discord播放音乐的play函数运行完全正常。更新后该函数返回Uncaught SyntaxError,后续还出现SyntaxError: Missing catch or finally after try报错,报错追踪指向ytdl-core的sig.js文件第116行,确认自身代码无问题,求助解决该异常。

原play函数代码

async function play(args) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
const stream =  ytdl(args, { filter: "audioonly", quality: "highestaudio", highWaterMark: 1 << 25 })
const resource = createAudioResource(stream)
connection.subscribe(player)
player.play(resource)  
console.log("yay")
await ytdl.getInfo(args).then(songInfo => {
var nom = {
title :songInfo.videoDetails.title,
url : songInfo.videoDetails.video_url,
mingnature : songInfo.videoDetails.thumbnails
}
console.log(nom.mingnature[0].url)
const exampleEmbed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle('**AudioPlayer**')
.setURL('https://youtu.be/dQw4w9WgXcQ')
.setDescription('__Le player joue de la musique !__')
.setImage(nom.mingnature[0].url)
.addFields({ name: '__Titre__', value: '\u200b' + nom.title, inline: true }, {name: "__Url__", value : "\u200B" + nom.url, inline : false})
.setTimestamp()
.setFooter({ text: 'Sponsorisé par le gouvernement chinois', iconURL: 'https://th.bing.com/th/id/R.28d8e003d4e8edb2f7d11d79ec49007b?rik=cuyzYTTdr2QpBQ&riu=http%3a%2f%2fwww.conservativehome.com%2fwp-content%2fuploads%2f2013%2f10%2fChinese-flag.jpg&ehk=IQVZcYPrGiV1wP4hGvjvss7uhK%2f6EQuXpmHL07sMpF4%3d&risl=&pid=ImgRaw&r=0' });
interaction.channel.send({embeds : [exampleEmbed]})
})
}

报错信息

初始报错

Uncaught SyntaxError evalmachine.<anonymous>:25
[])||(0,c[2])((0,c[45])((0,c[25])(c[21],c[55],(0,c[11])()),c[2],(0,c[86])(c[55],c[53]),c[13],c[77],c[27]),c[52],c[62],c[74]),1==c[43]&&((0,c[45])((0,c[2])((0,c[13])(c[65+Math.pow(3,2)%391],c[85]),c[78],c[35],c[68]),c[2],((0,c[76])(c[3],c[77]),c[40])(c[77]),c[40],c[87]),1)||(((((0,c[13])(c[87],c[65]),c[52])(c[46],c[Math.pow(5,3)%149+-51]),c[47])(c[63],c[1]),c[62])(c[50],c[18]),c[28])(c[56],c[50])};lma(ncode);
^

后续报错

SyntaxError: Missing catch or finally after try
at Script (vm:100:7)
at exports.decipherFormats (c:\Users\cash\Desktop\palaexpress bot\node_modules\ytdl-core\lib\sig.js:116:51)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
解决方法

方案1:降级到稳定版本

这是最直接的解决方案,新版本ytdl-core的签名解密逻辑可能存在bug,卸载当前版本后安装之前能正常运行的旧版本:

npm uninstall ytdl-core
npm install ytdl-core@[你之前使用的版本号]

如果不确定旧版本号,可以查看项目根目录下的package-lock.json文件,找到ytdl-core对应的版本字段。

方案2:检查Node.js版本兼容性

ytdl-core的新版本可能对Node.js版本有更高要求,确保你的Node.js版本在v16及以上(部分新版本要求v18+)。执行以下命令查看当前版本:

node -v

版本不符合的话,升级Node.js即可。

方案3:临时修复源码(不推荐)

找到项目中node_modules/ytdl-core/lib/sig.js文件的第116行,检查对应的try代码块,补充缺失的catch或finally语句。但注意这种修改会在重新安装依赖时被覆盖,仅适合临时应急使用。

内容的提问来源于stack exchange,提问作者Omegamax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 16:27:24