mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
@@ -47,10 +47,10 @@ class Role extends Base {
|
||||
this.hoist = data.hoist;
|
||||
|
||||
/**
|
||||
* The position of the role from the API
|
||||
* The raw position of the role from the API
|
||||
* @type {number}
|
||||
*/
|
||||
this.position = data.position;
|
||||
this.rawPosition = data.position;
|
||||
|
||||
/**
|
||||
* The permissions of the role
|
||||
@@ -126,8 +126,8 @@ class Role extends Base {
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get calculatedPosition() {
|
||||
const sorted = this.guild._sortedRoles;
|
||||
get position() {
|
||||
const sorted = this.guild._sortedRoles();
|
||||
return sorted.array().indexOf(sorted.get(this.id));
|
||||
}
|
||||
|
||||
@@ -264,21 +264,6 @@ class Role extends Base {
|
||||
return this.edit({ hoist }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* role.setPosition(1)
|
||||
* .then(r => console.log(`Role position: ${r.position}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setPosition(position, relative) {
|
||||
return this.guild.setRolePosition(this, position, relative).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the permissions of the role.
|
||||
* @param {PermissionResolvable[]} permissions The permissions of the role
|
||||
@@ -309,6 +294,31 @@ class Role extends Base {
|
||||
return this.edit({ mentionable }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of the role.
|
||||
* @param {number} position The position of the role
|
||||
* @param {Object} [options] Options for setting position
|
||||
* @param {boolean} [options.relative=false] Change the position relative to its current value
|
||||
* @param {boolean} [options.reason] Reasion for changing the position
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Set the position of the role
|
||||
* role.setPosition(1)
|
||||
* .then(r => console.log(`Role position: ${r.position}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setPosition(position, { relative, reason } = {}) {
|
||||
return Util.setPosition(this, position, relative,
|
||||
this.guild._sortedRoles(), this.client.api.guilds(this.guild.id).roles, reason)
|
||||
.then(updatedRoles => {
|
||||
this.client.actions.GuildRolesPositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
channels: updatedRoles,
|
||||
});
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the role.
|
||||
* @param {string} [reason] Reason for deleting this role
|
||||
|
||||
Reference in New Issue
Block a user