Skip to content

Commit

Permalink
Add support for the Get Guild Role endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Aug 16, 2024
1 parent c28c25e commit f759903
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Role> {
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<Vec<Role>> {
let mut value: Value = self
Expand Down
10 changes: 10 additions & 0 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http>, role_id: RoleId) -> Result<Role> {
http.as_ref().get_guild_role(self, role_id).await
}

/// Gets all of the guild's roles over the REST API.
///
/// # Errors
Expand Down

0 comments on commit f759903

Please sign in to comment.