diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index bbd8845026..84e4be4ea0 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -172,7 +172,9 @@ impl<'a> EditRole<'a> { }; if let Some(position) = self.position { - guild_id.edit_role_position(http, role.id, position, self.audit_log_reason).await?; + guild_id + .edit_role_positions(http, [(role.id, position)], self.audit_log_reason) + .await?; } Ok(role) } diff --git a/src/http/client.rs b/src/http/client.rs index 248b9b11fd..29fb4bce9f 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -2006,8 +2006,8 @@ impl Http { from_value(value).map_err(From::from) } - /// Changes the position of a role in a guild. - pub async fn edit_role_position( + /// Changes the positions of roles in a guild. + pub async fn edit_role_positions( &self, guild_id: GuildId, map: &impl serde::Serialize, diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index ead66460fc..0102373715 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -794,15 +794,28 @@ impl GuildId { builder.execute(http, self, sticker_id).await } - /// Edit the position of a [`Role`] relative to all others in the [`Guild`]. + /// Edits the position of [`Role`]s relative to all others in the [`Guild`]. /// /// **Note**: Requires the [Manage Roles] permission. /// /// # Examples /// - /// ```rust,ignore - /// use serenity::model::{GuildId, RoleId}; - /// GuildId::new(7).edit_role_position(&context, RoleId::new(8), 2); + /// ```rust,no_run + /// # use std::collections::HashMap; + /// # use serenity::http::Http; + /// use serenity::model::id::{GuildId, RoleId}; + /// + /// # async fn run() -> Result<(), Box> { + /// # let http: Http = unimplemented!(); + /// let roles = HashMap::from([ + /// (RoleId::new(8), 2), + /// (RoleId::new(10), 3), + /// (RoleId::new(11), 4), + /// (RoleId::new(25), 7), + /// ]); + /// GuildId::new(7).edit_role_positions(&http, roles, None); + /// # Ok(()) + /// # } /// ``` /// /// # Errors @@ -810,11 +823,10 @@ impl GuildId { /// Returns an [`Error::Http`] if the current user lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn edit_role_position( + pub async fn edit_role_positions( self, http: &Http, - role_id: RoleId, - position: i16, + roles: impl IntoIterator, reason: Option<&str>, ) -> Result> { #[derive(serde::Serialize)] @@ -827,12 +839,12 @@ impl GuildId { Maximum::AuditLogReason.check_overflow(reason.len())?; } - let map = EditRole { - id: role_id, + let iter = roles.into_iter().map(|(id, position)| EditRole { + id, position, - }; + }); - http.edit_role_position(self, &map, reason).await + http.edit_role_positions(self, &SerializeIter::new(iter), reason).await } /// Edits the guild's welcome screen. diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 26c9d3e2dc..e0166f0e71 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -1090,9 +1090,24 @@ impl Guild { /// /// Change the order of a role: /// - /// ```rust,ignore + /// ```rust,no_run + /// # use std::collections::HashMap; + /// # use serenity::http::Http; + /// # use serenity::model::guild::Guild; /// use serenity::model::id::RoleId; - /// guild.edit_role_position(&context, RoleId::new(8), 2); + /// + /// # async fn run() -> Result<(), Box> { + /// # let http: Http = unimplemented!(); + /// # let guild: Guild = unimplemented!(); + /// let roles = HashMap::from([ + /// (RoleId::new(8), 2), + /// (RoleId::new(10), 3), + /// (RoleId::new(11), 4), + /// (RoleId::new(25), 7), + /// ]); + /// guild.edit_role_positions(&http, roles, None); + /// # Ok(()) + /// # } /// ``` /// /// # Errors @@ -1100,14 +1115,13 @@ impl Guild { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn edit_role_position( + pub async fn edit_role_positions( &self, http: &Http, - role_id: RoleId, - position: i16, + roles: impl IntoIterator, audit_log_reason: Option<&str>, ) -> Result> { - self.id.edit_role_position(http, role_id, position, audit_log_reason).await + self.id.edit_role_positions(http, roles, audit_log_reason).await } /// Modifies a scheduled event in the guild with the data set, if any. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index 937a0943c5..462bf4f979 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -815,9 +815,24 @@ impl PartialGuild { /// /// Change the order of a role: /// - /// ```rust,ignore + /// ```rust,no_run + /// # use std::collections::HashMap; + /// # use serenity::http::Http; + /// # use serenity::model::guild::PartialGuild; /// use serenity::model::id::RoleId; - /// partial_guild.edit_role_position(&context, RoleId::new(8), 2); + /// + /// # async fn run() -> Result<(), Box> { + /// # let http: Http = unimplemented!(); + /// # let partial_guild: PartialGuild = unimplemented!(); + /// let roles = HashMap::from([ + /// (RoleId::new(8), 2), + /// (RoleId::new(10), 3), + /// (RoleId::new(11), 4), + /// (RoleId::new(25), 7), + /// ]); + /// partial_guild.edit_role_positions(&http, roles, None); + /// # Ok(()) + /// # } /// ``` /// /// # Errors @@ -825,14 +840,13 @@ impl PartialGuild { /// Returns [`Error::Http`] if the current user lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn edit_role_position( + pub async fn edit_role_positions( &self, http: &Http, - role_id: RoleId, - position: i16, + roles: impl IntoIterator, audit_log_reason: Option<&str>, ) -> Result> { - self.id.edit_role_position(http, role_id, position, audit_log_reason).await + self.id.edit_role_positions(http, roles, audit_log_reason).await } /// Edits a sticker.