So basically i know where the problem with my code is
export async function hourlyUpdate(bot:Discord.Client){
let result=new Promise<ActiveSubscriberList>(async (resolve,reject)=>{
let fileData=await getDataFromFile()
let resultList:ActiveSubscriberList={Server:[]}
fileData.channels.forEach(async(element,index)=>{
let tempArr=[]
element.subscriber.forEach(element => {
tempArr.push(element.userID)
})
let tempEntry={Channel:element.channelID,Subscriber:await actualFetch(bot,element.guildID,tempArr)}
resultList.Server.push(tempEntry)
})
resolve(resultList)
}).then(value=>{
})
return result
}
async function actualFetch(bot:Discord.Client,guildID:string,userArr:string[]){
let result= new Promise<string[]>(async (resolve)=>{
let activeSubs=[]
let tempSubArray=await bot.guilds.cache.get(guildID).members.fetch({ user: userArr, withPresences: true })
tempSubArray.forEach(element=>{
activeSubs.push(element.user.id)
})
resolve(activeSubs)
})
return result
}
I figured the problem lies within the loop continuing despite the result from the other async function is not reolved.
My question is if anybody has an idea on how to recode those loops, so that the whole function actually returns the result rather than empty objects.Any other comments, tips and advice on how to make this code better is appreciated too.