Hi there,
I have never really got the hang of scopes. I really hate it! Here I am inside an async function and I have an if/else statement where I define the variable ‘url’. But the code outside says that ‘url’ is undefined. WHY??? This is probably really simple, so if you could help me, I’d be sooooo grateful!
Code:
if(!validation){
const searchterm = message.content.split("!play ")
yts( searchterm[1], function ( err, r ) {
if ( err ) throw err
const videos = r.videos
var url = videos[0].url;
console.log(url); //outputs the URL I want
} )
}else{
var url = args[1];
console.log(url); //outputs the URL I want
}
console.log(url); //Outputs undefined
Hope you can help
Eddie