M
M
MoneySMile2020-12-30 16:51:06
Node.js
MoneySMile, 2020-12-30 16:51:06

Can't check for a role?

I can't figure out what's wrong!
I need to do something so that if a person has a role, then coins are added to him every 2 seconds
(And if you can tell me how to do it so that if a person has several roles, then the number of coins would be more

Mistake
C:\Users\f\Documents\GitHub\Panda_City\functions\biz.js:2
if(member.roles.cache.find(m => m.name === "Ларёк"))
^

TypeError: Cannot read property 'roles' of undefined
at Timeout.intervalFunc [as _onTimeout] (C:\Users\f\Documents\GitHub\Panda_City\functions\biz.js:2:19)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)

The code
function intervalFunc(bot,message,member,args) {
if(member.roles.cache.find(m => m.name === "Ларёк"))
{
coin[member.id].coin += 100
}
if(member.roles.cache.find(m => m.name === "Магазин «7 палочек бамбука»"))
{
coin[member.id].coin += 300
}
if(member.roles.cache.find(m => m.name === "Бамбуковая ферма"))
{
coin[member.id].coin += 800
}
}

setInterval(intervalFunc, 2000);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Nanavov, 2020-12-30
@fertyga098

The error says that you are trying to take a value by key from an object, but this object is jav. undefiend
if(member && member.roles.cache.find(m => m.name === "Stall"))
If you do this, the error will most likely disappear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question