1

我遇到了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.**');
} 

感谢您的时间。

4

2 回答 2

2

对我来说,诀窍是全局卸载软件包并重新安装。

> npm uninstall -g ytdl-core --save
> npm install ytdl-core
于 2020-06-06T21:38:36.557 回答
1

我不得不手动更新 ytdl-core,由于某种原因,npm install ytdl-core@latest没有更新模块。

于 2020-05-29T19:05:29.033 回答