-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_thread_message.rs
60 lines (54 loc) · 2.12 KB
/
create_thread_message.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! # Create Thread Message Example
//!
//! This example demonstrates how to create a discord webhook message inside a Forum Channels
//! thread that originated from a specific Webhook ID and Token. The arguments provided should
//! be provided exactly in that order.
//!
//! ## Example
//!
//! cargo run --example create_thread_message --features examples -- 00001111 aaaabbbb 22223333
//! where:
//! Webhook ID: 00001111
//! Token: aaaabbbb
//! Thread ID: 22223333
use std::{env, process};
use yadwh::message::MessageBuilder;
use yadwh::webhook::WebhookApi;
#[tokio::main]
async fn main() -> Result<(), yadwh::WebhookError> {
// Verify enough arguments were passed.
let args: Vec<String> = env::args().collect();
if args.len() < 4 {
println!("error: not enough arguments supplied.");
println!("usage: create_message [webhook_id] [token] [thread_id]");
process::exit(-1);
}
// Parse the arguments.
let webhook_id: String = args[1].to_string();
let token: String = args[2].to_string();
let thread_id: String = args[3].to_string();
// Message to be sent.
let message = MessageBuilder::new()
.username("Webhook Example")?
.content("Content portion of the message.")?
.embed(|embed| {
embed
.color("#cba6f7")
.author("Author Here", None, None, None)
.title("Title Here")
.description("Description Here\n```rust\nprintln!(\"Hello World!\");```")
.field("Field1", "Value1", None)
.field("Inline Field1", "Value1", Some(true))
.field("Inline Field2", "Value2", Some(true))
.field("Inline Field3", "Value3", Some(true))
.footer("Footer Here", None, None)
});
// Create the message.
println!("Creating message.");
let webhook = WebhookApi::new(&webhook_id, &token);
match webhook.message.create(&message, Some(&thread_id)).await {
Ok(resp) => println!("\nMessage created:\n{:#?}", resp),
Err(error) => println!("Error while creating: {}", error),
}
Ok(())
}