简体   繁体   中英

discord.js userinfo command show all roles

i am making a userinfo command and I want it to show all roles the user has. For the message sender i am using this: message.member.roles.cache.map(r => ' '+r.name+' ').join(' - ') but when i use it for the user the message author is mentioning ( let user = message.mentions.users.first() ) this is the code : user.member.roles.cache.map(r => ' '+r.name+' ').join(' - ') it gives this error: Cannot read property 'roles' of undefined I have asked on the discord.js discord but they weren't able to help me, Is there any way to make this work?

You're getting that error because user does not have a property called member . If you want to get the mentioned member, use this:

let member = message.mentions.members.first()

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