0

Sorry if it was worded badly, but im having an issue of, Im trying to calculate the amount of users in my db (adding them up per value), and after fetching the users with a forEach(), Im doing a wait(10000) [10 seconds], and it seems to be just not waiting.

let totalmembers = 0
function wait(ms) {
  var start = new Date().getTime();
  var end = start;
  while (end < start + ms) {
    end = new Date().getTime();
  }
}

client.diskey.forEach(async m => {
if(client.group.get(m) === null) return message.channel.send("not linked")
console.log("finished waiting")
await axios.get("https://groups.roblox.com/v1/groups/" + Number(client.group.get(m))).then(async gc => {

    await message.channel.send((gc.data.name + " : " + gc.data.memberCount + " : "))
    
  totalmembers = totalmembers + gc.data.memberCount


console.log(totalmembers)
wait(10000)
console.log("waiting")
await message.channel.send(totalmembers)
})
})

}

Any help appreciated.

Console

  • You probably want to do something more like [this](https://stackoverflow.com/a/45500721/6901876) when it comes to "waiting" before executing some code. Use `setTimeout` (with or without `Promise`s, depending on your intended functionality) instead of the `wait()` function. – Cannicide Dec 21 '20 at 22:02

1 Answers1

0

You can use a promise to simplify your wait() function, as shown in this answer. Make sure you also use await in front of wait(10000) to actually pause execution.

0mlml
  • 142
  • 8