Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!