Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want the discord bot to allow the command to be run only if the person has one of the roles in the array.

const validroles = ['owner', 'Co-Owner']

    if(!message.member.roles.includes(validroles)) {
      return message.channel.send(`**${message.author}, You do not have permission to use this command**`)
}

It gives me the error TypeError: message.member.roles.includes is not a function

How do I fix this?

question from:https://stackoverflow.com/questions/66056066/message-member-roles-includes-is-not-a-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

message.member.roles returns a manager for the roles belonging to this member, so you need to use the .cache property to return the roles. .cache returns a Collection that doesn't have an .includes() method. I think you were looking for the .has() property that checks if an element exists in the collection:

if (!message.member.roles.cache.has(validrole.id)) {
  return message.channel.send(`**${message.author}, You do not have permission to use this command**`)

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...