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

178
Views
How to set a role for a member list? discord.js v13

const membersWithRoleRadiant = message.guild.roles.cache.get('957714551011442781').members

membersWithRoleRadiant.roles.set(['955804233284878367']);

TypeError: Cannot read properties of undefined (reading 'set')

I received a list of participants with a specific role, I would like to set a different one for each.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Note: This is written for Discord.js v13.4.0.


.roles is not a property

Your issue is that you are calling the roles property on a Collection of GuildMember. This doesn't work because Collections are a Map but modified. You would have to perform .each() and apply the role that way. It'd look something like this:

membersWithRoleRadiant.each(member => member.roles.set(['IDHere']);

A small advisory as well. You should be careful when updating roles for a lot of users at once. This can be considered API spam which will cause Discord to rate limit or shut down your bot.

Reconsider using .set()

If you are only adding or removing roles, I strongly discourage the usage of .set(). That method will remove all their roles and replace it with the ones you have supplied. If you are adding roles, use the .add() method. Use the .remove() method when removing roles.

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!