ytdl()和 downloadFromInfo()函数都遇到问题。
错误:
TypeError_ [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined at validateString (internal/validators.js:107:11) at Url.parse (url.js:155:3) at Object.urlParse [as parse] (url.js:150:13) at doDownload (E:\Discord Bots\Astralis Time 2\node_modules\miniget\dist\index.js:90:28) at processTicksAndRejections (internal/process/task_queues.js:75:11)
对于 ytdl(),我检查了我的输入是否不正确,但事实并非如此。我相信ytdl-core尝试从 getInfo()函数读取对象时可能会有问题。
使用某些视频确实可以,但是这种情况很少见。
这是我使用的代码,我已经检查了所有变量,包括songInfo,而且它们似乎都正确,错误仅在运行 ytdl()或 downloadFromInfo( )。
async function playSong(channela, message){
var songInfo;
var songTitle;
let connection;
let dispatcher;
if(typeof servers[message.guild.id].queue[0] === 'undefined' || !servers[message.guild.id].queue[0] || typeof servers[message.guild.id].queue[0] !== 'string'){
servers[message.guild.id].queue.shift();
if(!servers[message.guild.id].queue[0]){
connection.disconnect();
message.member.voice.channel.leave();
}
}
try{
songInfo = await ytdl.getInfo(servers[message.guild.id].queue[0]);
songTitle = songInfo.title;
connection = await channela.join();
let stream = await ytdl.downloadFromInfo(songInfo, {filter: 'audioonly', quality: 'highestaudio', highWaterMark: 1<<25});
dispatcher = await connection.play(stream, {highWaterMark: 1});
}catch(error){
console.error('Could not play the video:' + error);
message.channel.send('**Please, try again.**');
}
谢谢您的时间。
答案 0 :(得分:2)
对我来说,诀窍是全局卸载软件包并重新安装。
> npm uninstall -g ytdl-core --save
> npm install ytdl-core
答案 1 :(得分:1)
由于某些原因,我不得不手动更新ytdl-core, npm install ytdl-core @ latest 并未更新模块。