use reqwest::Client;
use serde_json::json;
use std::error::Error;
#[allow(dead_code)]
pub async fn send_message(client: &Client, token: &str, channel_id: &str, content: &str) -> Result<(), Box<dyn Error>> {
let url = format!("https://discord.com/api/v9/channels/{}/messages", channel_id);
let body = json!({ "content": content });
client.post(&url)
.bearer_auth(token)
.json(&body)
.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 = 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 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(())
}