简体   繁体   中英

How to get the role of the author of a message with discord.js?

I am looking with help for a problem I am having with discord.js. I am making a discord bot, and I am trying to detect if the author of a message has a specific role or not using an if statement. I am using discord.js 12.0.2. I have tried both ways below:

message.member.roles.some(r => r.name === 'Admin')

message.member.roles.has('Admin')

However, I get an error message saying that 'some' is not a function. The same thing happens with 'has'. Looking through documentation and outdated stack overflow posts, I couldn't find any other way to do it. help would be much appreciated.

Thanks

Did you try member.roles.cache as per discord.js v12 documentation ?

message.member.roles.cache.some(r => r.name === 'Admin')

message.member.roles.cache.has('roleID')

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