M
M
MoneySMile2020-12-31 14:02:13
Node.js
MoneySMile, 2020-12-31 14:02:13

How to loop a node js function?

The function does not work for me.
What could be the problem?

the code
const biz = require('../biz.json')
const coin = require('../coin.json')

module.exports = async function(bots,user,message,member) {
        if(biz[member.id].biz1 == 1)
        {
            coin[member.id].coin += 100
        }
        if(biz[member.id].biz2 == 1)
        {
            coin[member.id].coin += 300 
        }
        if(biz[member.id].biz3 == 1)
        {
            coin[member.id].coin += 800 
        }
  
    await setInterval(intervalFunc, 5000);
}

mistake
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined
at module.exports (C:\Users\Alexander\Documents\GitHub\Panda_City\functions\biz.js:9:25)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2020-12-31
@SagePtr

setInterval does not return a promise, so it cannot be used with await

A
Alexander, 2020-12-31
@Alexandre888

How are you going to run this function without parameters?
until you assign any values ​​to the parameters, the bot will not know what to do with them.

setInterval(intervalFunc, 5000, значение параметра bots, значение параметра user, . . .)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question