简体   繁体   中英

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM