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

231
Views
TypeError: Cannot read properties of undefined (reading 'add')

I've been stuck on this for ages and can't figure out why the error pops up.

async function verify(i) {
    try {
        var g = await client.guilds.cache.get("943025185295044608");
        var r = await g.roles.cache.get("943202823217221652");
        var mem = await client.users.cache.get(i)
        
        mem.roles.add(r);
        client.channels.cache.get("944841210462367794").send(`${mem} was verified`)
    } catch (e) {
        client.channels.cache.get("944841210462367794").send(`${mem} was not verified`)
        console.log(g)
        console.log(r)
        console.log(mem)
        console.log(e)
    }
}

When I console.log it comes up with the variable as defined. Ive tried doing await but that doesnt work. Im also working in discord.js v12

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks to Ivar I got my answer mem is a User. Users don't have roles. GuildMembers have roles. So I changed client.users.cache.get(i) to g.members.cache.get(i)

about 4 years ago · Juan Pablo Isaza Report
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!