dsc_commands_remover/
lib.rs1use reqwest::{header::AUTHORIZATION, Client};
2
3pub const EMPTY_JSON_ARRAY: &serde_json::Value = &serde_json::json!([]);
5
6pub async fn remove_commands(
8 application_id: &str,
9 bot_token: &str,
10 guild_id: &Option<String>,
11) -> Result<(), reqwest::Error> {
12 let url = match guild_id {
13 Some(guild_id) => {
14 format!(
16 "https://discord.com/api/v10/applications/{}/guilds/{}/commands",
17 application_id, guild_id,
18 )
19 }
20 None => {
21 format!(
23 "https://discord.com/api/v10/applications/{}/commands",
24 application_id
25 )
26 }
27 };
28
29 call_command_api(&url, bot_token).await
30}
31
32pub async fn call_command_api(url: &String, bot_token: &str) -> Result<(), reqwest::Error> {
33 let client = Client::new();
34
35 let res = client
36 .put(url)
37 .header(AUTHORIZATION, format!("Bot {}", bot_token))
38 .json(EMPTY_JSON_ARRAY)
39 .send()
40 .await?;
41
42 res.error_for_status()?;
43 Ok(())
44}