I'm experiencing an issue with both ytdl( ) and downloadFromInfo( ) functions.
Error:
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)
In the case of ytdl( ) I checked if my input was incorrect, but it wasn't. I believe there may be a problem when ytdl-core tries to read the object from the getInfo( ) function.
With some videos it does work, but those cases are rare.
This is the code I use, I have checked all my variables, including songInfo and they all seem to be correct, the error only appears when I run ytdl( ) or 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.**');
}
Thank you for your time.
For me the trick was to globally uninstall the package and install it back.
> npm uninstall -g ytdl-core --save
> npm install ytdl-core