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

234
Visualizações
Discord.js get 2nd mention

I have this command where I want to get the 2nd mention (Role2).

!command [Role1] [Role2]

I know that I can get the first role with this code:

const role1 = message.mentions.roles.first();

But I couldn't find anything for the 2nd mention, nor could anyone tell me how to do it. I hope anyone can help me with this issue.

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

0

message.mentions.roles is a Collection, and that has a .at() method.

const role2 = message.mentions.roles.at(1) // index 1 is the second value

Note the roles may not be in the right order, so it's a good idea to use regex, and map by getting from cache

// import MessageMentions class from discord.js module
const roles = message.content.match(MessageMentions.ROLES_PATTERN).map(r => message.guild.roles.cache.get(r.slice(3, r.length - 1))
const role2 = roles[1]
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