mirror of
https://github.com/discordjs/discord.js.git
synced 2026-06-02 09:00:07 +00:00
serious role position stuff (#1159)
* serious role position stuff * kill meh * Update Role.js * Update Guild.js * Update Role.js
This commit is contained in:
@@ -48,7 +48,7 @@ class Role {
|
||||
this.hoist = data.hoist;
|
||||
|
||||
/**
|
||||
* The position of the role in the role manager
|
||||
* The position of the role from the API
|
||||
* @type {number}
|
||||
*/
|
||||
this.position = data.position;
|
||||
@@ -122,6 +122,16 @@ class Role {
|
||||
return clientMember.highestRole.comparePositionTo(this) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The position of the role in the role manager
|
||||
* @type {number}
|
||||
*/
|
||||
get calculatedPosition() {
|
||||
const sorted = this.guild.roles.array()
|
||||
.sort((r1, r2) => r1.position !== r2.position ? r1.position - r2.position : r1.id - r2.id);
|
||||
return sorted.indexOf(sorted.find(r => r.id === this.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an object mapping permission names to whether or not the role enables that permission
|
||||
* @returns {Object<string, boolean>}
|
||||
@@ -246,6 +256,7 @@ class Role {
|
||||
/**
|
||||
* Set the position of the role
|
||||
* @param {number} position The position of the role
|
||||
* @param {boolean} [relative=false] Move the position relative to its current value
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // set the position of the role
|
||||
@@ -253,8 +264,8 @@ class Role {
|
||||
* .then(r => console.log(`Role position: ${r.position}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setPosition(position) {
|
||||
return this.guild.setRolePosition(this, position).then(() => this);
|
||||
setPosition(position, relative) {
|
||||
return this.guild.setRolePosition(this, position, relative).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user