Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Returning value from an mutliple async array in javascript

I feel that this problem has been asked before maybe I have a unique scenario I haven't seen on github before, but I am fetching data from multiple sources at the same time which is create multiple arrays I need to loop through to grab the data needed. I am looking to return the value of a simple array of twitch channels and have the value only logged once. Instead my logs are looping over empty arrays which is definitely unnecessary.


client.on("ready", async () => {
  const endeavorsServer = client.guilds.cache.get(process.env.DISCORD_GUILD_TOKEN)
  const connectedChannels = []
  let value
  let grabMembers = []

  // Fetch and get the list named 'members'
  await endeavorsServer.members.fetch().then((members) => {
    grabMembers = members
  })

  // Loop through every members
  grabMembers.forEach(async (member) => {
    value = await newMembers(member)
  })

  console.log(value)
  if (value && value.length) {
    console.log('val', value)
  }
})

async function newMembers(member) {
  const liveRoleId = process.env.DISCORD_LIVE_ROLE_ID
  const isBot = member.user.bot
  const liveRole = member.roles.cache.has(liveRoleId)
  let array = []
  let value = null
  if (!isBot && /* liveRole */ (member.user.username === 'member_id')) {
    value = await getDiscordUser(member.user)
  }

  if (value && value.twitch_channel) {
    array.push(value.twitch_channel)
  }
  return array
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!