Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setRolePositions function #3317

Merged
merged 1 commit into from Jun 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/structures/Guild.js
Expand Up @@ -967,6 +967,40 @@ class Guild extends Base {
);
}

/**
* The data needed for updating a guild role's position
* @typedef {Object} GuildRolePosition
* @property {GuildRoleResolveable} role The ID of the role
* @property {number} position The position to update
*/

/**
* Batch-updates the guild's role positions
* @param {GuildRolePosition[]} rolePositions Role positions to update
* @returns {Promise<Guild>}
* @example
* guild.setRolePositions([{ role: roleID, position: updatedRoleIndex }])
* .then(guild => console.log(`Role permissions updated for ${guild}`))
* .catch(console.error);
*/
setRolePositions(rolePositions) {
// Make sure rolePositions are prepared for API
rolePositions = rolePositions.map(o => ({
id: o.role,
position: o.position,
}));

// Call the API to update role positions
return this.client.api.guilds(this.id).roles.patch({
data: rolePositions,
}).then(() =>
this.client.actions.GuildRolePositionUpdate.handle({
guild_id: this.id,
roles: rolePositions,
}).guild
);
}

/**
* Edits the guild's embed.
* @param {GuildEmbedData} embed The embed for the guild
Expand Down