'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



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pixel