diff options
| author | Austin Hellyer <[email protected]> | 2016-11-18 11:00:45 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-18 11:00:45 -0800 |
| commit | cf128b1a10d0636c8b4b5233d46b068cfe665688 (patch) | |
| tree | f36b1cd08d00cec69a76eb10c493ab3b86d61678 /src/utils/builder/execute_webhook.rs | |
| parent | Feature macros should use else as block separator (diff) | |
| download | serenity-cf128b1a10d0636c8b4b5233d46b068cfe665688.tar.xz serenity-cf128b1a10d0636c8b4b5233d46b068cfe665688.zip | |
A bit of docs
Diffstat (limited to 'src/utils/builder/execute_webhook.rs')
| -rw-r--r-- | src/utils/builder/execute_webhook.rs | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/utils/builder/execute_webhook.rs b/src/utils/builder/execute_webhook.rs index d2a14aa..a434057 100644 --- a/src/utils/builder/execute_webhook.rs +++ b/src/utils/builder/execute_webhook.rs @@ -10,7 +10,47 @@ use std::default::Default; /// 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`]: +/// +/// ```rust,no_run +/// use serenity::client::http; +/// use serenity::model::Embed; +/// use serenity::utils::Colour; +/// +/// let id = 245037420704169985; +/// let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV"; +/// +/// let webhook = http::get_webhook_with_token(id, token) +/// .expect("valid webhook"); +/// +/// 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(|f| f +/// .inline(false) +/// .name("The Rust Book") +/// .value("A comprehensive resource for all topics related to Rust")) +/// .field(|f| f +/// .inline(false) +/// .name("Rust by Example") +/// .value("A collection of Rust examples on topics, useable in-browser"))); +/// +/// let _ = webhook.execute(|w| w +/// .content("Here's some information on Rust:") +/// .embeds(vec![website, resources])); +/// ``` +/// /// [`Webhook`]: ../model/struct.Webhook.html +/// [`Webhook::execute`]: ../../model/struct.Webhook.html#method.execute /// [`execute_webhook`]: ../client/http/fn.execute_webhook.html pub struct ExecuteWebhook(pub ObjectBuilder); @@ -21,11 +61,28 @@ impl ExecuteWebhook { } /// Set the content of the message. + /// + /// Note that when setting at least one embed via [`embeds`], this may be + /// omitted. + /// + /// [`embeds`]: #method.embeds pub fn content(self, content: &str) -> Self { ExecuteWebhook(self.0.insert("content", content)) } - // Set the embeds associated with the message. + /// 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. + /// + /// [`Embed::fake`]: ../../model/struct.Embed.html#method.fake + /// [`Webhook::execute`]: ../../model/struct.Webhook.html#method.execute + /// [struct-level documentation]: #examples pub fn embeds(self, embeds: Vec<Value>) -> Self { ExecuteWebhook(self.0.insert("embeds", embeds)) } @@ -46,9 +103,12 @@ impl ExecuteWebhook { impl Default for ExecuteWebhook { /// Returns a default set of values for a [`Webhook`] execution. /// - /// The only default value is `tts` being set to `true`. In the event that + /// The only default value is [`tts`] being set to `true`. In the event that /// there is a bug that Discord defaults `tts` to `true`, at least /// serenity.rs won't be a part of it. + /// + /// [`Webhook`]: ../../model/struct.Webhook.html + /// [`tts`]: #method.tts fn default() -> ExecuteWebhook { ExecuteWebhook(ObjectBuilder::new().insert("tts", false)) } |