简体   繁体   中英

I am unable to check if a member has a certain role in Discord.js

I am working on a bot, that has a request interaction and I want to check if the user interacting has a certain role. I keep getting this crash:

TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.

Here's the code:

client.on("interactionCreate", interaction => {
if (interaction.isButton() && interaction.customId === 'request') {
     if (interaction.member.roles.cache.find(r => r.id === 'ROLEID') {
          const bannedRequestEmbed = {
            "title": "Request",
            "description": "Sorry, but you are no longer allowed to send requests.",
            "color": 16711680}
        interaction.reply({ embeds: [bannedRequestEmbed], ephemeral: true })
     }
}

尝试检查角色时,可以使用以下命令:

member.roles.cache.has(roleID)

要检查交互成员是否具有角色,您可以使用:

interaction.member.roles.cache.some(r => r.id === "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