Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
How do i mention two roles in discord.js v13
const role = message.guild.roles.cache.find(role => role.name === ['Muted' || 'muted'])

The code above is for a mute (and unmute) command. Normally servers have the M capital or small which affects the role in the coding. With the code above it returns an error saying Unknown code

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

For starters, let's look at what your code is actually doing.

const role = message.guild.roles.cache.find(role => role.name === ['Muted' || 'muted'])

This code is equivalent to

const role = message.guild.roles.cache.find(role => role.name === ['Muted'])

because "string" || "otherString" evaluates to "string". Note that this comparison will always fail, because different arrays can't be compared using the === operator.

["muted"] === ["muted"] // this is false

If you want to do checks against arrays you'll need to implement some iterative logic yourself or use one of the useful helpers like Array#some and Array#includes.

The correct way to do a case-insensetive comparison would probably be something like

const role = 
  message.guild.roles.cache.find(role => role.name.toLowerCase() === "muted")

If you really only want to support Muted or muted (and not mUtEd for example), your method can work with a small tweak.

const role 
  = message.guild.roles.cache.find(role => ["muted","Muted"].includes(role.name))
//                                         ^ anonymous array of acceptable values 
about 4 years ago · Juan Pablo Isaza Relatório

0

Lowercase the role name and compare it to a lowercase string

const role = message.guild.roles.cache
   .find(role => role.name.toLowerCase() == 'muted');

If you ever do need to check a string array for possible role names use Array#includes()

const role = message.guild.roles.cache
   .find(role => ['foo', 'bar', 'baz'].includes(role.name));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda