Create channels() for Guild
This method retrieves all channels from a guild
This commit is contained in:
parent
84505829c4
commit
1fb3ef6766
|
@ -148,6 +148,60 @@ impl Guild {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a `Result` containing a vector of `Channel` structs if the request was successful, or an `InstanceServerError` if there was an error.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `url_api` - A string slice that holds the URL of the API.
|
||||||
|
/// * `token` - A string slice that holds the authorization token.
|
||||||
|
/// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits.
|
||||||
|
/// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits.
|
||||||
|
///
|
||||||
|
pub async fn channels(
|
||||||
|
&self,
|
||||||
|
url_api: &str,
|
||||||
|
token: &str,
|
||||||
|
limits_user: &mut Limits,
|
||||||
|
limits_instance: &mut Limits,
|
||||||
|
) -> Result<Vec<Channel>, InstanceServerError> {
|
||||||
|
let request = Client::new()
|
||||||
|
.get(format!(
|
||||||
|
"{}/guilds/{}/channels/",
|
||||||
|
url_api,
|
||||||
|
self.id.to_string()
|
||||||
|
))
|
||||||
|
.bearer_auth(token);
|
||||||
|
let result = match LimitedRequester::new()
|
||||||
|
.await
|
||||||
|
.send_request(
|
||||||
|
request,
|
||||||
|
crate::api::limits::LimitType::Guild,
|
||||||
|
limits_instance,
|
||||||
|
limits_user,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
};
|
||||||
|
let stringed_response = match result.text().await {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(e) => {
|
||||||
|
return Err(InstanceServerError::InvalidResponseError {
|
||||||
|
error: e.to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let _: Vec<Channel> = match from_str(&stringed_response) {
|
||||||
|
Ok(result) => return Ok(result),
|
||||||
|
Err(e) => {
|
||||||
|
return Err(InstanceServerError::InvalidResponseError {
|
||||||
|
error: e.to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
|
|
Loading…
Reference in New Issue