[−][src]Struct serenity::model::webhook::Webhook
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
id: WebhookId
The unique Id.
Can be used to calculate the creation date of the webhook.
avatar: Option<String>
The default avatar.
This can be modified via ExecuteWebhook::avatar
.
channel_id: ChannelId
The Id of the channel that owns the webhook.
guild_id: Option<GuildId>
The Id of the guild that owns the webhook.
name: Option<String>
The default name of the webhook.
This can be modified via ExecuteWebhook::username
.
token: String
The webhook's secure token.
user: Option<User>
The user that created the webhook.
Note: This is not received when getting a webhook by its token.
Methods
impl Webhook
[src]
pub 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.
pub fn edit(
&mut self,
http: impl AsRef<Http>,
name: Option<&str>,
avatar: Option<&str>
) -> Result<()>
[src]
&mut self,
http: impl AsRef<Http>,
name: Option<&str>,
avatar: Option<&str>
) -> Result<()>
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.as_ref().get_webhook_with_token(id, token) .expect("valid webhook"); let _ = webhook.edit(&http, Some("new name"), None).expect("Error editing");
Setting a webhook's avatar:
let id = 245037420704169985; let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV"; let mut webhook = http.as_ref().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(&http, None, Some(&image)).expect("Error editing");
pub fn execute<F>(
&self,
http: impl AsRef<Http>,
wait: bool,
f: F
) -> Result<Option<Message>> where
F: FnOnce(&mut ExecuteWebhook) -> &mut ExecuteWebhook,
[src]
&self,
http: impl AsRef<Http>,
wait: bool,
f: F
) -> Result<Option<Message>> where
F: FnOnce(&mut ExecuteWebhook) -> &mut ExecuteWebhook,
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::Http; let id = 245037420704169985; let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV"; let mut webhook = http.as_ref().get_webhook_with_token(id, token) .expect("valid webhook"); let _ = webhook.execute(&http, false, |mut w| { w.content("test"); w });
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.as_ref().get_webhook_with_token(id, token) .expect("valid webhook"); 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 }); let _ = webhook.execute(&http, false, |mut w| { w.content("test"); w.username("serenity"); w.embeds(vec![embed]); w });
pub 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.
Trait Implementations
impl Clone for Webhook
[src]
fn clone(&self) -> Webhook
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Webhook
[src]
impl Serialize for Webhook
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for Webhook
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Sync for Webhook
impl Send for Webhook
impl Unpin for Webhook
impl RefUnwindSafe for Webhook
impl UnwindSafe for Webhook
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Send + Sync> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
T: Any,