pub struct ExecuteWebhook<'a> { /* private fields */ }
Expand description

Execute a webhook, sending a message to its channel.

The message must include at least one of attachments, components, content, or embeds.

Examples

use twilight_http::Client;
use twilight_model::id::Id;

let client = Client::new("my token".to_owned());
let id = Id::new(432);

client
    .execute_webhook(id, "webhook token")
    .content("Pinkie...")?
    .await?;

Implementations

Specify the AllowedMentions for the message.

Unless otherwise called, the request will use the client’s default allowed mentions. Set to None to ignore this default.

Attach multiple files to the message.

Calling this method will clear any previous calls.

Errors

Returns an error of type AttachmentDescriptionTooLarge if the attachments’s description is too large.

Returns an error of type AttachmentFilename if any filename is invalid.

The URL of the avatar of the webhook.

Set the message’s list of Components.

Calling this method will clear previous calls.

Requires a webhook owned by the application.

Errors

Refer to the errors section of twilight_validate::component::component for a list of errors that may be returned as a result of validating each provided component.

Set the message’s content.

The maximum length is 2000 UTF-16 characters.

Errors

Returns an error of type ContentInvalid if the content length is too long.

Set the message’s list of embeds.

Calling this method will clear previous calls.

The amount of embeds must not exceed EMBED_COUNT_LIMIT. The total character length of each embed must not exceed EMBED_TOTAL_LENGTH characters. Additionally, the internal fields also have character limits. Refer to Discord Docs/Embed Limits for more information.

Errors

Returns an error of type TooManyEmbeds if there are too many embeds.

Otherwise, refer to the errors section of twilight_validate::embed::embed for a list of errors that may occur.

Set the message’s flags.

The only supported flag is SUPPRESS_EMBEDS.

JSON encoded body of any additional request fields.

If this method is called, all other fields are ignored, except for attachments. See Discord Docs/Uploading Files.

Without payload_json:

use twilight_http::Client;
use twilight_model::id::Id;
use twilight_util::builder::embed::EmbedBuilder;

let client = Client::new("token".to_owned());

let message = client
    .execute_webhook(Id::new(1), "token here")
    .content("some content")?
    .embeds(&[EmbedBuilder::new().title("title").validate()?.build()])?
    .wait()
    .await?
    .model()
    .await?;

assert_eq!(message.content, "some content");

With payload_json:

use twilight_http::Client;
use twilight_model::id::Id;
use twilight_util::builder::embed::EmbedBuilder;

let client = Client::new("token".to_owned());

let message = client
    .execute_webhook(Id::new(1), "token here")
    .content("some content")?
    .payload_json(br#"{ "content": "other content", "embeds": [ { "title": "title" } ] }"#)
    .wait()
    .await?
    .model()
    .await?;

assert_eq!(message.content, "other content");

Execute in a thread belonging to the channel instead of the channel itself.

Set the name of the created thread when used in a forum channel.

Specify true if the message is TTS.

Specify the username of the webhook’s message.

Errors

Returns an error of type WebhookUsername if the webhook’s name is invalid.

Wait for the message to send before sending a response. See Discord Docs/Execute Webhook.

Using this will result in receiving the created message.

👎Deprecated since 0.14.0: use .await or into_future instead

Execute the request, returning a future resolving to a Response.

Trait Implementations

The output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
Try to convert a request builder into a raw Request. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
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