use reqwest::Client;
use serde_json::Value;
use std::error::Error;
#[allow(dead_code)]
pub async fn fetch_channel_info(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn modify_channel(client: &Client, token: &str, channel_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
client.patch(&url)
.bearer_auth(token)
.json(&settings)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_channel(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_channel_messages(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn get_channel_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn crosspost_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/crosspost", channel_id, message_id);
client.post(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn create_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/@me", channel_id, message_id, emoji);
client.put(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_own_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/@me", channel_id, message_id, emoji);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_user_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/{}", channel_id, message_id, emoji, user_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_reactions(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions", channel_id, message_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn delete_all_reactions(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions", channel_id, message_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_all_reactions_for_emoji(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}", channel_id, message_id, emoji);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn edit_message(client: &Client, token: &str, channel_id: &str, message_id: &str, new_content: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
let body = serde_json::json!({ "content": new_content });
client.patch(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn delete_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn bulk_delete_messages(client: &Client, token: &str, channel_id: &str, message_ids: Vec<&str>) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/bulk-delete", channel_id);
let body = serde_json::json!({ "messages": message_ids });
client.post(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn edit_channel_permissions(client: &Client, token: &str, channel_id: &str, overwrite_id: &str, permissions: Value) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/permissions/{}", channel_id, overwrite_id);
client.put(&url)
.bearer_auth(token)
.json(&permissions)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_channel_invites(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/invites", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn create_channel_invite(client: &Client, token: &str, channel_id: &str, invite_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/invites", channel_id);
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&invite_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn delete_channel_permission(client: &Client, token: &str, channel_id: &str, overwrite_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/permissions/{}", channel_id, overwrite_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn follow_announcement_channel(client: &Client, token: &str, channel_id: &str, webhook_channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/followers", channel_id);
let body = serde_json::json!({ "webhook_channel_id": webhook_channel_id });
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn trigger_typing_indicator(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/typing", channel_id);
client.post(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_pinned_messages(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/pins", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn pin_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/pins/{}", channel_id, message_id);
client.put(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn unpin_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/pins/{}", channel_id, message_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn group_dm_add_recipient(client: &Client, token: &str, channel_id: &str, user_id: &str, access_token: &str, nick: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/recipients/{}", channel_id, user_id);
let body = serde_json::json!({ "access_token": access_token, "nick": nick });
client.put(&url)
.bearer_auth(token)
.json(&body)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn group_dm_remove_recipient(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/recipients/{}", channel_id, user_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn start_thread_from_message(client: &Client, token: &str, channel_id: &str, message_id: &str, thread_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/threads", channel_id, message_id);
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&thread_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn start_thread_without_message(client: &Client, token: &str, channel_id: &str, thread_settings: Value) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/threads", channel_id);
let response: Value = client.post(&url)
.bearer_auth(token)
.json(&thread_settings)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn join_thread(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/thread-members/@me", channel_id);
client.put(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn add_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_id, user_id);
client.put(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn remove_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_id, user_id);
client.delete(&url)
.bearer_auth(token)
.send()
.await?
.error_for_status()?;
Ok(())
}
#[allow(dead_code)]
pub async fn get_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_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_thread_members(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/thread-members", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn list_public_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/threads/archived/public", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn list_private_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/threads/archived/private", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}
#[allow(dead_code)]
pub async fn list_joined_private_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/users/@me/threads/archived/private", channel_id);
let response: Value = client.get(&url)
.bearer_auth(token)
.send()
.await?
.json()
.await?;
Ok(response)
}