From f759903475ded07ab689113d4df05196a3ab8ec8 Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Fri, 16 Aug 2024 15:46:51 -0400 Subject: [PATCH] Add support for the Get Guild Role endpoint --- src/http/client.rs | 23 +++++++++++++++++++++++ src/model/guild/guild_id.rs | 10 ++++++++++ 2 files changed, 33 insertions(+) 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