Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
[package]
name = "webhook"
version = "2.1.2"
edition = "2018"
authors = ["Thomas"]
edition = "2024"
description = "Discord Webhook API Wrapper"
readme = "README.md"
repository = "https://github.com/thoo0224/webhook-rs"
license = "MIT"
keywords = ["discord", "discord-api", "webhook", "discord-webhook"]
authors = ["Thomas"]
publish = true

exclude = [
"examples/*",
".env"
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
categories = ["api-bindings"]
exclude = ["examples/*"]

[features]
default = ["client"]
Expand All @@ -24,12 +18,17 @@ full = ["client", "models"]
models = []

[dependencies]
hyper = { version = "0.14.16", features = ["client", "http1", "http2", "tcp"], optional = true }
hyper = { version = "0.14.16", features = [
"client",
"http1",
"http2",
"tcp",
], optional = true }
hyper-tls = { version = "0.5.0", features = ["vendored"], optional = true }

serde = { version = "1.0.131", features = ["derive"] }
serde_json = "1.0.72"

[dev-dependencies]
tokio = { version = "1.14.0", features = ["full"] }
dotenv = "0.15.0"
dotenv = "0.15.0"
61 changes: 36 additions & 25 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use webhook::client::{WebhookClient, WebhookResult};
use webhook::models::NonLinkButtonStyle;

const IMAGE_URL: &'static str = "https://cdn.discordapp.com/avatars/312157715449249795/a_b8b3b0c35f3dee2b6586a0dd58697e29.png";
const IMAGE_URL: &str =
"https://cdn.discordapp.com/avatars/312157715449249795/a_b8b3b0c35f3dee2b6586a0dd58697e29.png";

#[tokio::main]
async fn main() -> WebhookResult<()> {
Expand All @@ -12,26 +13,36 @@ async fn main() -> WebhookResult<()> {
let webhook_info = client.get_information().await?;
println!("webhook: {:?}", webhook_info);

client.send(|message| message
.content("@everyone")
.username("Thoo")
.avatar_url(IMAGE_URL)
.embed(|embed| embed
.title("Webhook")
.description("Hello, World!")
.footer("Footer", Some(String::from(IMAGE_URL)))
.image(IMAGE_URL)
.thumbnail(IMAGE_URL)
.author("Lmao#0001", Some(String::from(IMAGE_URL)), Some(String::from(IMAGE_URL)))
.field("name", "value", false))).await?;
client
.send(|message| {
message
.content("@everyone")
.username("Thoo")
.avatar_url(IMAGE_URL)
.embed(|embed| {
embed
.title("Webhook")
.description("Hello, World!")
.footer("Footer", Some(String::from(IMAGE_URL)))
.image(IMAGE_URL)
.thumbnail(IMAGE_URL)
.author(
"Lmao#0001",
Some(String::from(IMAGE_URL)),
Some(String::from(IMAGE_URL)),
)
.field("name", "value", false)
})
})
.await?;

application_webhook_example(&url).await?;

Ok(())
}

// to try out using application webhook run:
// `application_webhook_example(&url).await?;`
async fn application_webhook_example(url: &str) -> WebhookResult<()> {
let client = WebhookClient::new(&url);
let client = WebhookClient::new(url);
let webhook_info = client.get_information().await?;
println!("webhook: {:?}", webhook_info);

Expand All @@ -48,17 +59,17 @@ async fn application_webhook_example(url: &str) -> WebhookResult<()> {
.emoji("625891304081063986", "mage", false)
.custom_id("id_0")
})
.regular_button(|button| {
button
.style(NonLinkButtonStyle::Secondary)
.label("Secondary!")
.emoji("625891304081063986", "mage", false)
.custom_id("id_1")
})
.link_button(|button| button.label("Click Me!").url("https://discord.com"))
.regular_button(|button| {
button
.style(NonLinkButtonStyle::Secondary)
.label("Secondary!")
.emoji("625891304081063986", "mage", false)
.custom_id("id_1")
})
.link_button(|button| button.label("Click Me!").url("https://discord.com"))
})
})
.await?;

Ok(())
}
}
Loading