Function serenity::http::execute_webhook[][src]

pub fn execute_webhook(
    webhook_id: u64,
    token: &str,
    wait: bool,
    map: &Map<String, Value>
) -> Result<Option<Message>>

Executes a webhook, posting a Message in the webhook's associated Channel.

This method does not require authentication.

Pass true to wait to wait for server confirmation of the message sending before receiving a response. From the Discord docs:

waits for server confirmation of message send before response, and returns the created message body (defaults to false; when false a message that is not saved does not return an error)

The map can optionally contain the following data:

  • avatar_url: Override the default avatar of the webhook with a URL.
  • tts: Whether this is a text-to-speech message (defaults to false).
  • username: Override the default username of the webhook.

Additionally, at least one of the following must be given:

  • content: The content of the message.
  • embeds: An array of rich embeds.

Note: For embed objects, all fields are registered by Discord except for height, provider, proxy_url, type (it will always be rich), video, and width. The rest will be determined by Discord.

Examples

Sending a webhook with message content of test:

This example is not tested
extern crate serde_json;
extern crate serenity;

use serde_json::builder::ObjectBuilder;
use serenity::http;

let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let map = ObjectBuilder::new().insert("content", "test").build();

let message = match http::execute_webhook(id, token, true, map) {
    Ok(Some(message)) => message,
    Ok(None) => {
        println!("Expected a webhook message");

        return;
    },
    Err(why) => {
        println!("Error executing webhook: {:?}", why);

        return;
    },
};