[][src]Struct serenity::model::webhook::Webhook

pub struct Webhook {
    pub id: WebhookId,
    pub avatar: Option<String>,
    pub channel_id: ChannelId,
    pub guild_id: Option<GuildId>,
    pub name: Option<String>,
    pub token: String,
    pub user: Option<User>,
}

A representation of a webhook, which is a low-effort way to post messages to channels. They do not necessarily require a bot user or authentication to use.

Fields

The unique Id.

Can be used to calculate the creation date of the webhook.

The default avatar.

This can be modified via ExecuteWebhook::avatar.

The Id of the channel that owns the webhook.

The Id of the guild that owns the webhook.

The default name of the webhook.

This can be modified via ExecuteWebhook::username.

The webhook's secure token.

The user that created the webhook.

Note: This is not received when getting a webhook by its token.

Methods

impl Webhook
[src]

Deletes the webhook.

As this calls the http::delete_webhook_with_token function, authentication is not required.

Edits the webhook in-place. All fields are optional.

To nullify the avatar, pass Some(""). Otherwise, passing None will not modify the avatar.

Refer to http::edit_webhook for httprictions on editing webhooks.

As this calls the http::edit_webhook_with_token function, authentication is not required.

Examples

Editing a webhook's name:

use serenity::http;

let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";

let mut webhook = http::get_webhook_with_token(id, token)
    .expect("valid webhook");

let _ = webhook.edit(Some("new name"), None).expect("Error editing");

Setting a webhook's avatar:

use serenity::http;

let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";

let mut webhook = http::get_webhook_with_token(id, token)
    .expect("valid webhook");

let image = serenity::utils::read_image("./webhook_img.png")
    .expect("Error reading image");

let _ = webhook.edit(None, Some(&image)).expect("Error editing");

Executes a webhook with the fields set via the given builder.

The builder provides a method of setting only the fields you need, without needing to pass a long set of arguments.

Examples

Execute a webhook with message content of test:

use serenity::http;

let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";

let mut webhook = http::get_webhook_with_token(id, token)
    .expect("valid webhook");

let _ = webhook.execute(false, |w| w.content("test")).expect("Error executing");

Execute a webhook with message content of test, overriding the username to serenity, and sending an embed:

use serenity::http;
use serenity::model::channel::Embed;

let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";

let mut webhook = http::get_webhook_with_token(id, token)
    .expect("valid webhook");

let embed = Embed::fake(|e| e
    .title("Rust's website")
    .description("Rust is a systems programming language that runs
                  blazingly fast, prevents segfaults, and guarantees
                  thread safety.")
    .url("https://rust-lang.org"));

let _ = webhook.execute(false, |w| w
    .content("test")
    .username("serenity")
    .embeds(vec![embed]))
    .expect("Error executing");

Retrieves the latest information about the webhook, editing the webhook in-place.

As this calls the http::get_webhook_with_token function, authentication is not required.

Trait Implementations

impl Clone for Webhook
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Webhook
[src]

Formats the value using the given formatter. Read more

impl Serialize for Webhook
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for Webhook
[src]

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

impl Send for Webhook

impl Sync for Webhook

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any