TypeError: Cannot read property 'add' of undefined Discord.js javascript

Viewed 69

I am working on a mute command and got this error

TypeError: Cannot read property 'add' of undefined

This is my code

const person = message.mentions.users.first() 
person.roles.add(muterole.id)

I have tried: person.addRole but it also doesnt work and person.roles.add(muterole) but it also doesnt work

Any Idea why? thanks

1 Answers

You have to use message.mentions.members.first(). A User doesn't have any role, because it represents a user on Discord, and a Member has roles, it represents a User in a Guild (another answer).

const person = message.mentions.members.first() 
person.roles.add(muterole.id)
Related