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
}