简体   繁体   中英

How do I check if there is a role that contains certain text in it?

Let me explain: I want to search through all the roles in the guild to find a role that contains the text "Mod", ie "MODerator".

This is the code I have right now:

client.on('message', msg => {
      if (msg.author == client.user){return}
      let message = msg.content.toLowerCase()
      let allowedRole = msg.guild.roles.cache.find(r => r.name === "Mod");
      if (message.includes("e!"))
      {

        if (message.includes('automod') && allowedRole)
        {
          if (automodOn)
          {
            automodOn = false;
            msg.channel.send("Automod has been `deactivated`.")
          }
          else
          {
            automodOn = true;
            msg.channel.send("Automod has been `activated`.")
          }
        }

What this code does is searching for a role that it's name is specifically "Mod". What I need it to do, as I already said, is for it to search for a role containing the text "Mod".

Thanks in advance.

const allowedRole = msg.guild.roles.cache.find(r => r.name.includes("Mod"));

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