0

Code:

client.on('message', message => {
    if (message.content.startsWith(`${prefix2}red`)){
    if (message.member.roles.cache.some(role => role.name === 'Red')) return message.channel.send(`You already have the role!`)
    let role = message.guild.roles.find(r => r.name === "Red");(r => r.name === "Red");
    let member = message.member;
    message.delete(1)
    member.addRole(role).catch(console.error)
    }   
})

I am trying to make a command that will give the user that role.
Error:

let role = message.guild.roles.find(r => r.name === "Red");
                                       ^

TypeError: message.guild.roles.find is not a function
YaBoiPingu
  • 71
  • 2
  • 10

1 Answers1

2

Use message.guild.roles.cache.find.

Tarazed
  • 1,707
  • 1
  • 7
  • 22
  • like that `let role = message.guild.roles.cache.find(r => r.name === "Red");(r => r.name === "Red");` – YaBoiPingu Apr 02 '20 at 13:48
  • 1
    I'm not sure why you have the condition twice. – Tarazed Apr 02 '20 at 14:00
  • i changed `let role = message.guild.roles.find(r => r.name === "red"); to let role = message.guild.roles.cache.find(r => r.name === "Red");` and i am getting `TypeError [INVALID_TYPE]: Supplied options is not an object` – YaBoiPingu Apr 03 '20 at 10:32