mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
Fix setting guild role positions (#751)
This commit is contained in:
@@ -630,6 +630,32 @@ class Guild {
|
||||
return this.client.rest.methods.deleteGuild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of a role in this guild
|
||||
* @param {string|Role} role the role to edit, can be a role object or a role ID.
|
||||
* @param {number} position the new position of the role
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setRolePosition(role, position) {
|
||||
if (role instanceof Role) {
|
||||
role = role.id;
|
||||
} else if (typeof role !== 'string') {
|
||||
return Promise.reject(new Error('Supplied role is not a role or string'));
|
||||
}
|
||||
|
||||
position = Number(position);
|
||||
if (isNaN(position)) {
|
||||
return Promise.reject(new Error('Supplied position is not a number'));
|
||||
}
|
||||
|
||||
const updatedRoles = this.roles.array().map(r => ({
|
||||
id: r.id,
|
||||
position: r.id === role ? position : (r.position < position ? r.position : r.position + 1),
|
||||
}));
|
||||
|
||||
return this.client.rest.methods.setRolePositions(this.id, updatedRoles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this Guild equals another Guild. It compares all properties, so for most operations
|
||||
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
||||
|
||||
@@ -230,7 +230,7 @@ class Role {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setPosition(position) {
|
||||
return this.client.rest.methods.updateGuildRole(this, { position });
|
||||
return this.guild.setRolePosition(this, position);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user