diff --git a/src/http/client.rs b/src/http/client.rs index b8a18cd08e3..04a9eb0c47a 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -3772,6 +3772,29 @@ impl Http { .await } + /// Retrieves a specific role in a [`Guild`]. + pub async fn get_guild_role(&self, guild_id: GuildId, role_id: RoleId) -> Result { + let mut value: Value = self + .fire(Request { + body: None, + multipart: None, + headers: None, + method: LightMethod::Get, + route: Route::GuildRole { + guild_id, + role_id, + }, + params: None, + }) + .await?; + + if let Some(map) = value.as_object_mut() { + map.insert("guild_id".to_string(), guild_id.get().into()); + } + + from_value(value).map_err(From::from) + } + /// Retrieves a list of roles in a [`Guild`]. pub async fn get_guild_roles(&self, guild_id: GuildId) -> Result> { let mut value: Value = self diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index a810c4ef243..3b4b67c5dd6 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -899,6 +899,16 @@ impl GuildId { builder.execute(cache_http, self).await } + /// Gets a specific role in the guild, by Id. + /// + /// # Errors + /// + /// Returns [`Error::Http`] if the current user is not in the guild, or if the role does not + /// exist. + pub async fn role(self, http: impl AsRef, role_id: RoleId) -> Result { + http.as_ref().get_guild_role(self, role_id).await + } + /// Gets all of the guild's roles over the REST API. /// /// # Errors