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

#[non_exhaustive]
pub struct Webhook { pub id: WebhookId, pub kind: WebhookType, pub avatar: Option<String>, pub channel_id: ChannelId, pub guild_id: Option<GuildId>, pub name: Option<String>, pub token: Option<String>, pub user: Option<User>, }
Expand description

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 (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct {{ .. }} syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
id: WebhookId
Expand description

The unique Id.

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

kind: WebhookType
Expand description

The type of the webhook.

avatar: Option<String>
Expand description

The default avatar.

This can be modified via ExecuteWebhook::avatar_url.

channel_id: ChannelId
Expand description

The Id of the channel that owns the webhook.

guild_id: Option<GuildId>
Expand description

The Id of the guild that owns the webhook.

name: Option<String>
Expand description

The default name of the webhook.

This can be modified via ExecuteWebhook::username.

token: Option<String>
Expand description

The webhook’s secure token.

user: Option<User>
Expand description

The user that created the webhook.

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

Implementations

impl Webhook[src]

pub async fn delete(&self, http: impl AsRef<Http>) -> Result<()>[src]

Deletes the webhook.

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

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the webhook does not exist, the token is invalid, or if the webhook could not otherwise be deleted.

pub async fn edit(
    &mut self,
    http: impl AsRef<Http>,
    name: Option<&str>,
    avatar: Option<&str>
) -> Result<()>
[src]

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:


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

let mut webhook = http.get_webhook_with_token(id, token).await?;

webhook.edit(&http, Some("new name"), None).await?;

Setting a webhook’s avatar:

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

let mut webhook = http.get_webhook_with_token(id, token).await?;

let image = serenity::utils::read_image("./webhook_img.png")?;

webhook.edit(&http, None, Some(&image)).await?;

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the content is malformed, or if the token is invalid.

Or may return an Error::Json if there is an error in deserialising Discord’s response.

pub async fn execute<'a, F>(
    &self,
    http: impl AsRef<Http>,
    wait: bool,
    f: F
) -> Result<Option<Message>> where
    F: FnOnce(&'b mut ExecuteWebhook<'a>) -> &'b mut ExecuteWebhook<'a>, 
[src]

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:

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

let mut webhook = http.get_webhook_with_token(id, token).await?;

webhook.execute(&http, false, |mut w| {
    w.content("test");
    w
})
.await?;

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

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

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

let mut webhook = http.get_webhook_with_token(id, token).await?;

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

webhook.execute(&http, false, |mut w| {
    w.content("test");
    w.username("serenity");
    w.embeds(vec![embed]);
    w
})
.await?;

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the content is malformed, or if the webhook’s token is invalid.

Or may return an Error::Json if there is an error deserialising Discord’s response.

pub async fn edit_message<F>(
    &self,
    http: impl AsRef<Http>,
    message_id: MessageId,
    f: F
) -> Result<Message> where
    F: FnOnce(&mut EditWebhookMessage) -> &mut EditWebhookMessage
[src]

Edits a webhook message with the fields set via the given builder.

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the content is malformed, the webhook’s token is invalid, or the given message Id does not belong to the current webhook.

Or may return an Error::Json if there is an error deserialising Discord’s response.

pub async fn delete_message(
    &self,
    http: impl AsRef<Http>,
    message_id: MessageId
) -> Result<()>
[src]

Deletes a webhook message.

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the webhook’s token is invalid or the given message Id does not belong to the current webhook.

pub async fn refresh(&mut self, http: impl AsRef<Http>) -> Result<()>[src]

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.

Errors

Returns an Error::Model if the Self::token is None.

May also return an Error::Http if the http client errors or if Discord returns an error. Such as if the Webhook was deleted.

Or may return an Error::Json if there is an error deserialising Discord’s response.

pub fn url(&self) -> Result<String>[src]

Returns the url of the webhook.

assert_eq!(hook.url(), "https://discord.com/api/webhooks/245037420704169985/ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV")

Errors

Returns an Error::Model if the Self::token is None.

Trait Implementations

impl Clone for Webhook[src]

fn clone(&self) -> Webhook[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Webhook[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Serialize for Webhook[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl RefUnwindSafe for Webhook

impl Send for Webhook

impl Sync for Webhook

impl Unpin for Webhook

impl UnwindSafe for Webhook

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 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, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V

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