I try to add a role to a user by ID, but I always receive this error
user.roles.add(role)
^
TypeError: Cannot read properties of undefined (reading 'add')
Here is my code
let role = Guild.roles.cache.find((r) => r.name === dataobj.Guild.name);
client.users.fetch(useritem).then((user) => {
user.roles.add(role)
.catch(error => { })
});
dataobj.Guild.name
is the name of the role.
useritem
is the ID of the user.
var role
is correct and output the right role.
Var user
is correct and output the right user.
I tried many things, but nothing works.
Thank for your help.