This is a simplified version of my code
1| client.on("message", async message => {
2| if( ... ){
3| let object = null
4| if(object === null) object = await getObj() // <- Returns a promise
5|
6| let variable = object.property
My problem is that since line 3
is null, line 4
gets executed, and getObj
is a async local function. But for some reason the code does not wait for line 4
to return a promise but instead keeps on running causing line 6
's object to be null. Meaning I am receiving a "Cannot read property id of null" error
Here is a simplified version of getObj
async function getObj(){
let clt = a event
clt.on("collect", msg => {
return a object
})
clt.on("end", clted => {
if(clted.size === 0){
return null
}
})
}
Here is the raw version of my code: https://sourceb.in/PdGSJCf3x1