ytdl() error: The "url" argument must be of type string. Received type undefined
ytdl() error: The "url" argument must be of type string. Received type undefined
我在使用 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.**');
}
感谢您的宝贵时间。
我不得不手动更新 ytdl-core,出于某种原因,npm install ytdl-core@latest 没有更新模块。
对我来说,诀窍是全局卸载软件包并重新安装它。
> npm uninstall -g ytdl-core --save
> npm install ytdl-core
我在使用 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.**');
}
感谢您的宝贵时间。
我不得不手动更新 ytdl-core,出于某种原因,npm install ytdl-core@latest 没有更新模块。
对我来说,诀窍是全局卸载软件包并重新安装它。
> npm uninstall -g ytdl-core --save
> npm install ytdl-core