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

Viewed 49

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 })
     }
}
2 Answers

To check if the interaction member has a role, you can use:

interaction.member.roles.cache.some(r => r.id === "ROLEID")

When trying to check for a role, you can use this:

member.roles.cache.has(roleID)
Related