Please describe the problem you are having in as much detail as possible:
Currently there is the guild.roles property which outputs the roles of the server sorted by ID. It would be nice if along with this we could get a guild.rolesHierarchy which outputs the roles by ID sorted on their hierarchy within the guild.
Include a reproducible code sample here, if possible:
Currently in order to get the highest role the easiest method that I have found is as follows. Possibly this may also be possible directly with Collection.Sort(), however I could not figure out how to apply the sorting to the Collection
message.guild.roles.find(
'position',
parseInt(message.guild.roles
.map(rp => rp.position)
.sort((a, b) => a - b)
.slice(-1)))
Clarification for this code and how it works:
We want to find the role that has the highest position. To do that we use Collection.find() based on the position property of the role. For the value of the position we want the highest one possible. To find the highest possible position of all roles on the server we map all roles by their position using Collection.map(). This array can then be sorted using ES6 Array.Sort() and by slicing off all but the last we get the highest possible position. All of this has to be parsed to an integer to be usable for Collection.find('Position', ...) as position expects a number.
Further details:
We chose not to implement this because you can do it in one line:
collectionOfRolesOrChannels.sort((a, b) => a.position - b.position || a.id - b.id);
Oh.. well that shows my lacking understanding of the Collection.sort that I mentioned. Closing then I suppose.
Most helpful comment
We chose not to implement this because you can do it in one line: