Rust_Discord_API/utils/
embed.rs

1use reqwest::Client;
2use serde_json::json;
3use std::error::Error;
4
5/// Sends an embed message to a specified Discord channel.
6///
7/// # Arguments
8///
9/// * `client` - The HTTP client used to send the request.
10/// * `token` - The bot token for authentication.
11/// * `channel_id` - The ID of the channel to send the embed message to.
12/// * `title` - The title of the embed.
13/// * `description` - The description of the embed.
14///
15/// # Returns
16///
17/// A result indicating success or failure.
18#[allow(dead_code)]
19pub async fn send_embed_message(client: &Client, token: &str, channel_id: &str, title: &str, description: &str) -> Result<(), Box<dyn Error>> {
20    let url = format!("https://discord.com/api/v9/channels/{}/messages", channel_id);
21    let embed = json!({
22        "title": title,
23        "description": description,
24        "color": 0x3498db // Example color
25    });
26    let body = json!({ "embed": embed });
27    
28    client.post(&url)
29        .bearer_auth(token)
30        .json(&body)
31        .send()
32        .await?
33        .error_for_status()?;
34    
35    Ok(())
36}