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 support for the Get Guild Role endpoint #2946

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading