use reqwest::Client;
use serde_json::Value;
use std::error::Error;
#[allow(dead_code)]
pub async fn create_guild(client: &Client, token: &str, guild_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = "https://discord.com/api/v9/guilds";
let response: Value = client.post(url)
.bearer_auth(token)
.json(&guild_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_preview(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/preview", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_guild(client: &Client, token: &str, guild_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_channels(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn create_guild_channel(client: &Client, token: &str, guild_id: &str, channel_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&channel_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_channel_positions(client: &Client, token: &str, guild_id: &str, positions: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&positions)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn list_active_guild_threads(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/threads/active", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn list_guild_members(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn search_guild_members(client: &Client, token: &str, guild_id: &str, query: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/search?query={}", guild_id, query);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn add_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str, member_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
let response: Value = client.put(&url)
.bearer_auth(token)
.json(&member_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_current_member(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/@me", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_current_user_nick(client: &Client, token: &str, guild_id: &str, nick: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/@me/nick", guild_id);
let body = serde_json::json!({ "nick": nick });
client.patch(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn add_guild_member_role(client: &Client, token: &str, guild_id: &str, user_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}/roles/{}", guild_id, user_id, role_id);
client.put(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn remove_guild_member_role(client: &Client, token: &str, guild_id: &str, user_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}/roles/{}", guild_id, user_id, role_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn remove_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_bans(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/bans", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn create_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str, ban_settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
client.put(&url)
.bearer_auth(token)
.json(&ban_settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn remove_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn bulk_guild_ban(client: &Client, token: &str, guild_id: &str, user_ids: Vec<&str>) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/bans", guild_id);
let body = serde_json::json!({ "user_ids": user_ids });
client.post(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_roles(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn create_guild_role(client: &Client, token: &str, guild_id: &str, role_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&role_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_role_positions(client: &Client, token: &str, guild_id: &str, positions: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&positions)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_guild_role(client: &Client, token: &str, guild_id: &str, role_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/roles/{}", guild_id, role_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_guild_mfa_level(client: &Client, token: &str, guild_id: &str, level: u8) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/mfa", guild_id);
let body = serde_json::json!({ "level": level });
client.post(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_guild_role(client: &Client, token: &str, guild_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/roles/{}", guild_id, role_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_prune_count(client: &Client, token: &str, guild_id: &str, days: u8) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/prune?days={}", guild_id, days);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn begin_guild_prune(client: &Client, token: &str, guild_id: &str, days: u8) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/prune", guild_id);
let body = serde_json::json!({ "days": days });
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_voice_regions(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/regions", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_invites(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/invites", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_integrations(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/integrations", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn delete_guild_integration(client: &Client, token: &str, guild_id: &str, integration_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/integrations/{}", guild_id, integration_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_widget_settings(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/widget", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_widget_settings(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/widget", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
#[allow(unused_variables)] pub async fn get_guild_widget(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/widget.json", guild_id);
let response: Value = client.get(&url)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_vanity_url(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/vanity-url", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
#[allow(unused_variables)] pub async fn get_guild_widget_image(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/widget.png", guild_id);
let response: Value = client.get(&url)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_guild_welcome_screen(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/welcome-screen", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_welcome_screen(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/welcome-screen", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_guild_onboarding(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/onboarding", guild_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_guild_onboarding(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/onboarding", guild_id);
client.put(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_current_user_voice_state(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/voice-states/@me", guild_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn modify_user_voice_state(client: &Client, token: &str, guild_id: &str, user_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/guilds/{}/voice-states/{}", guild_id, user_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}