mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
refactor: move Guild setPositions methods to managers (#6875)
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user