Struct serenity::builder::ExecuteWebhook [−][src]
pub struct ExecuteWebhook<'a>(pub HashMap<&'static str, Value>, pub Vec<AttachmentType<'a>>);
Expand description
A builder to create the inner content of a Webhook
’s execution.
This is a structured way of cleanly creating the inner execution payload, to reduce potential argument counts.
Refer to the documentation for execute_webhook
on restrictions with
execution payloads and its fields.
Examples
Creating two embeds, and then sending them as part of the delivery
payload of Webhook::execute
:
use serenity::http::Http;
use serenity::model::channel::Embed;
use serenity::utils::Colour;
let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let webhook = http.get_webhook_with_token(id, token).await?;
let website = Embed::fake(|e| {
e.title("The Rust Language Website")
.description("Rust is a systems programming language.")
.colour(Colour::from_rgb(222, 165, 132))
});
let resources = Embed::fake(|e| {
e.title("Rust Resources")
.description("A few resources to help with learning Rust")
.colour(0xDEA584)
.field("The Rust Book", "A comprehensive resource for Rust.", false)
.field("Rust by Example", "A collection of Rust examples", false)
});
webhook
.execute(&http, false, |w| {
w.content("Here's some information on Rust:").embeds(vec![website, resources])
})
.await?;
Tuple Fields
0: HashMap<&'static str, Value>
1: Vec<AttachmentType<'a>>
Implementations
Override the default avatar of the webhook with an image URL.
Examples
Overriding the default avatar:
let avatar_url = "https://i.imgur.com/KTs6whd.jpg";
webhook.execute(&http, false, |w| w.avatar_url(avatar_url).content("Here's a webhook")).await?;
Set the content of the message.
Note that when setting at least one embed via Self::embeds
, this may be
omitted.
Examples
Sending a webhook with a content of "foo"
:
let execution = webhook.execute(&http, false, |w| w.content("foo")).await;
if let Err(why) = execution {
println!("Err sending webhook: {:?}", why);
}
Appends a file to the webhook message.
pub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
pub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
Appends a list of files to the webhook message.
pub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
pub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
Sets a list of files to include in the webhook message.
Calling this multiple times will overwrite the file list.
To append files, call Self::add_file
or Self::add_files
instead.
Set the embeds associated with the message.
This should be used in combination with Embed::fake
, creating one
or more fake embeds to send to the API.
Examples
Refer to the struct-level documentation for an example on how to use embeds.
Whether the message is a text-to-speech message.
Examples
Sending a webhook with text-to-speech enabled:
let execution = webhook.execute(&http, false, |w| w.content("hello").tts(true)).await;
if let Err(why) = execution {
println!("Err sending webhook: {:?}", why);
}
Override the default username of the webhook.
Examples
Overriding the username to "hakase"
:
let execution = webhook.execute(&http, false, |w| w.content("hello").username("hakase")).await;
if let Err(why) = execution {
println!("Err sending webhook: {:?}", why);
}
Sets the flags for the message.
Examples
Supressing an embed on the message.
let execution = webhook
.execute(&http, false, |w| {
w.content("https://docs.rs/serenity/latest/serenity/")
.flags(MessageFlags::SUPPRESS_EMBEDS)
})
.await;
if let Err(why) = execution {
println!("Err sending webhook: {:?}", why);
}
Trait Implementations
Returns a default set of values for a Webhook
execution.
The only default value is Self::tts
being set to false
.
Examples
Creating an ExecuteWebhook
builder:
use serenity::builder::ExecuteWebhook;
let executor = ExecuteWebhook::default();
Auto Trait Implementations
impl<'a> !RefUnwindSafe for ExecuteWebhook<'a>
impl<'a> Send for ExecuteWebhook<'a>
impl<'a> Sync for ExecuteWebhook<'a>
impl<'a> Unpin for ExecuteWebhook<'a>
impl<'a> !UnwindSafe for ExecuteWebhook<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more