简体   繁体   中英

Discord.js if user has role?

I need help with my bot. My bot should only respond if a user has a specific role. It should be definable by name and not by ID. I user Discord.js 12.0.2

my code

//DBD embed
client.on("message", async message => {
  let cmd = message
    if (message.content === '/code-embed') {
      message.channel.send("Der angefragte Bot code", { files: [ "./dbd/embed.txt" ] })
}})

you can use some() on the roles collection of the GuildMember to check if they have a specific role.

if (!message.member.roles.cache.some((role) => role.name === 'RoleName')) return

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