我遇到了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.**');
}
感谢您的时间。