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.
Note: This is written for Discord.js v13.4.0.
.roles is not a propertyYour 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.
.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.