Implement get() for channel

This commit is contained in:
bitfl0wer 2023-05-23 14:37:34 +02:00
parent 9afce452a6
commit 8808e5554f
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
1 changed files with 31 additions and 1 deletions

View File

@ -199,5 +199,35 @@ impl types::Channel {
}
}
pub async fn get() {}
pub async fn get(
token: &str,
url_api: &str,
guild_id: &str,
limits_user: &mut Limits,
limits_instance: &mut Limits,
) -> Result<types::Channel, InstanceServerError> {
let request = Client::new()
.get(format!("{}/guilds/{}/channels/", url_api, guild_id))
.bearer_auth(token);
let mut requester = LimitedRequester::new().await;
let result = match requester
.send_request(
request,
crate::api::limits::LimitType::Guild,
limits_instance,
limits_user,
)
.await
{
Ok(result) => result,
Err(e) => return Err(e),
};
match from_str::<types::Channel>(&result.text().await.unwrap()) {
Ok(object) => Ok(object),
Err(e) => Err(InstanceServerError::RequestErrorError {
url: url_api.to_string(),
error: e.to_string(),
}),
}
}
}