How to get the roles of user who messaged in discord.js?

Member

by jerad , in category: Javascript , 2 months ago

How to get the roles of user who messaged in discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 2 months ago

@jerad 

To get the roles of the user who messaged in Discord using discord.js, you can follow these steps:

  1. Get the message object from the message event:
1
2
3
client.on('message', message => {
  // Your code here
});


  1. Get the member object from the message:
1
const member = message.guild.member(message.author);


  1. Get the roles of the member:
1
const roles = member.roles.cache;


  1. Now you can access the roles of the user who messaged by iterating over the roles collection:
1
2
3
roles.forEach(role => {
  console.log(role.name);
});


By following these steps, you can get the roles of the user who messaged in Discord using discord.js.