Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  12] [ 2]  / answers: 1 / hits: 18657  / 5 Years ago, sat, november 9, 2019, 12:00:00

How would you get all the roles in a server using Discord.js? I've message.guild.roles but from there it's a mystery to me.


More From » discord.js

 Answers
15

As stated by the other answer and your question message.guild indeed has a property roles:



.roles

A collection of roles that are in this guild. The key is the role's ID, the value is the role

Type: Collection <Snowflake, Role>



A collection has extends the JavaScript type map and had some function for you to use.


You indeed have all the roles of the guild (server) with message.guild.roles.

Now if you want to do anything with it, for example list them, check the function in Collection / the type map.


message.guild.roles.forEach(role => console.log(role.name, role.id))

will print each role name + id in the console.


[#51493] Friday, November 1, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
agustindejonm

Total Points: 738
Total Questions: 84
Total Answers: 84

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
agustindejonm questions
Fri, Jun 25, 21, 00:00, 3 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Sat, May 16, 20, 00:00, 4 Years ago
;