This repository has been archived on 2023-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
2023-04-02 13:26:38 +02:00

25 lines
756 B
Rust

use serde::Deserialize;
use twilight_http::Client;
pub mod commands;
pub mod interactions;
#[derive(Deserialize)]
struct ClientCredentialsResponse {
access_token: String,
}
fn client_credentials_grant(authorization: String) -> anyhow::Result<ClientCredentialsResponse> {
Ok(ureq::post("https://discord.com/api/v10/oauth2/token")
.set("Authorization", &format!("Basic {}", authorization))
.send_form(&[
("grant_type", "client_credentials"),
("scope", "applications.commands.update"),
])?.into_json()?)
}
pub fn discord_client(authorization: String) -> anyhow::Result<Client> {
let token = client_credentials_grant(authorization)?.access_token;
Ok(Client::new(format!("Bearer {token}")))
}