diff --git a/src/builder/create_scheduled_event.rs b/src/builder/create_scheduled_event.rs index 27967bb5f7f..9107e68a559 100644 --- a/src/builder/create_scheduled_event.rs +++ b/src/builder/create_scheduled_event.rs @@ -120,8 +120,8 @@ impl CreateScheduledEvent { /// /// # Errors /// - /// May error if the icon is a URL and the HTTP request fails, or if the image is a file - /// on a path that doesn't exist. + /// May error if a URL is given and the HTTP request fails, or if a path is given to a file + /// that does not exist. #[cfg(feature = "http")] pub async fn image<'a>( mut self, @@ -133,6 +133,14 @@ impl CreateScheduledEvent { Ok(self) } + /// Sets the cover image for the scheduled event. Requires the input be a base64-encoded image + /// that is in either JPG, GIF, or PNG format. + #[cfg(not(feature = "http"))] + pub fn image(mut self, image: String) -> Self { + self.image = Some(image); + self + } + /// Creates a new scheduled event in the guild with the data set, if any. /// /// **Note**: Requres the [Manage Events] permission. diff --git a/src/builder/create_webhook.rs b/src/builder/create_webhook.rs index abf4c106fe1..ef36a62a305 100644 --- a/src/builder/create_webhook.rs +++ b/src/builder/create_webhook.rs @@ -4,6 +4,8 @@ use crate::http::{CacheHttp, Http}; use crate::internal::prelude::*; #[cfg(feature = "http")] use crate::model::prelude::*; +#[cfg(feature = "http")] +use crate::utils::encode_image; #[derive(Clone, Debug, Serialize)] pub struct CreateWebhook { @@ -34,8 +36,26 @@ impl CreateWebhook { self } + /// Set the webhook's default avatar. + /// + /// # Errors + /// + /// May error if a URL is given and the HTTP request fails, or if a path is given to a file + /// that does not exist. + #[cfg(feature = "http")] + pub async fn avatar<'a>( + mut self, + http: impl AsRef, + avatar: impl Into>, + ) -> Result { + let avatar_data = avatar.into().data(&http.as_ref().client).await?; + self.avatar = Some(encode_image(&avatar_data)); + Ok(self) + } + /// Set the webhook's default avatar. Requires the input be a base64-encoded image that is in /// either JPG, GIF, or PNG format. + #[cfg(not(feature = "http"))] pub fn avatar(mut self, avatar: String) -> Self { self.avatar = Some(avatar); self diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index f305aad4040..a6e8e3051fe 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -144,8 +144,8 @@ impl EditRole { /// /// # Errors /// - /// May error if the icon is a URL and the HTTP request fails, or if the icon is a file - /// on a path that doesn't exist. + /// May error if a URL is given and the HTTP request fails, or if a path is given to a file + /// that does not exist. #[cfg(feature = "model")] pub async fn icon<'a>( &mut self, @@ -159,4 +159,13 @@ impl EditRole { Ok(self) } + + /// The image to set as the role icon. Requires the input be a base64-encoded image that is in + /// either JPG, GIF, or PNG format. + #[cfg(not(feature = "model"))] + pub fn icon(&mut self, icon: String) -> &mut Self { + self.icon = Some(icon); + self.unicode_emoji = None; + self + } } diff --git a/src/builder/edit_scheduled_event.rs b/src/builder/edit_scheduled_event.rs index 86233ee00e6..eb279e1bb1b 100644 --- a/src/builder/edit_scheduled_event.rs +++ b/src/builder/edit_scheduled_event.rs @@ -141,8 +141,8 @@ impl EditScheduledEvent { /// /// # Errors /// - /// May error if the icon is a URL and the HTTP request fails, or if the image is a file - /// on a path that doesn't exist. + /// May error if a URL is given and the HTTP request fails, or if a path is given to a file + /// that does not exist. #[cfg(feature = "model")] pub async fn image<'a>( &mut self, @@ -153,4 +153,12 @@ impl EditScheduledEvent { self.image = Some(encode_image(&image_data)); Ok(self) } + + /// Sets the cover image for the scheduled event. Requires the input be a base64-encoded image + /// that is in either JPG, GIF, or PNG format. + #[cfg(not(feature = "model"))] + pub fn image(&mut self, image: String) -> &mut Self { + self.image = Some(image); + self + } } diff --git a/src/builder/edit_webhook.rs b/src/builder/edit_webhook.rs index 905da73173d..dc4ba197610 100644 --- a/src/builder/edit_webhook.rs +++ b/src/builder/edit_webhook.rs @@ -52,8 +52,26 @@ impl<'a> EditWebhook<'a> { self } + /// Set the webhook's default avatar. + /// + /// # Errors + /// + /// May error if a URL is given and the HTTP request fails, or if a path is given to a file + /// that does not exist. + #[cfg(featuer = "http")] + pub async fn avatar( + mut self, + http: impl AsRef, + avatar: impl Into>, + ) -> Result { + let avatar_data = avatar.into().data(&http.as_ref().client).await?; + self.avatar = Some(Some(encode_image(&avatar_data))); + Ok(self) + } + /// Set the webhook's default avatar. Requires the input be a base64-encoded image that is in /// either JPG, GIF, or PNG format. + #[cfg(not(feature = "http"))] pub fn avatar(mut self, avatar: String) -> Self { self.avatar = Some(Some(avatar)); self