refactor: move Guild setPositions methods to managers (#6875)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Rodry
2021-10-26 20:28:56 +01:00
committed by GitHub
parent b27888455f
commit e12a5b6a0c
4 changed files with 61 additions and 28 deletions

View File

@@ -218,6 +218,32 @@ class RoleManager extends CachedManager {
return clone;
}
/**
* Batch-updates the guild's role positions
* @param {GuildRolePosition[]} rolePositions Role positions to update
* @returns {Promise<Guild>}
* @example
* guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
* .then(guild => console.log(`Role positions updated for ${guild}`))
* .catch(console.error);
*/
async setPositions(rolePositions) {
// Make sure rolePositions are prepared for API
rolePositions = rolePositions.map(o => ({
id: this.resolveId(o.role),
position: o.position,
}));
// Call the API to update role positions
await this.client.api.guilds(this.id).roles.patch({
data: rolePositions,
});
return this.client.actions.GuildRolesPositionUpdate.handle({
guild_id: this.id,
roles: rolePositions,
}).guild;
}
/**
* Gets the managed role a user created when joining the guild, if any
* <info>Only ever available for bots</info>