25 lines
756 B
Rust
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}")))
|
|
}
|