Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed embeds to be optional in followup messages #2968

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/builder/create_interaction_response_followup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CreateInteractionResponseFollowup<'a> {
// [Omitting avatar_url: not supported in interaction followups]
#[serde(skip_serializing_if = "Option::is_none")]
tts: Option<bool>,
embeds: Cow<'a, [CreateEmbed<'a>]>,
embeds: Option<Cow<'a, [CreateEmbed<'a>]>>,
#[serde(skip_serializing_if = "Option::is_none")]
allowed_mentions: Option<CreateAllowedMentions<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -41,7 +41,7 @@ impl<'a> CreateInteractionResponseFollowup<'a> {

#[cfg(feature = "http")]
fn check_length(&self) -> Result<(), ModelError> {
super::check_lengths(self.content.as_deref(), Some(&self.embeds), 0)
super::check_lengths(self.content.as_deref(), self.embeds.as_deref(), 0)
}

/// Set the content of the message.
Expand Down Expand Up @@ -87,13 +87,13 @@ impl<'a> CreateInteractionResponseFollowup<'a> {

/// Adds an embed to the message.
pub fn add_embed(mut self, embed: CreateEmbed<'a>) -> Self {
self.embeds.to_mut().push(embed);
self.embeds.get_or_insert_with(Cow::default).to_mut().push(embed);
self
}

/// Adds multiple embeds to the message.
pub fn add_embeds(mut self, embeds: impl IntoIterator<Item = CreateEmbed<'a>>) -> Self {
self.embeds.to_mut().extend(embeds);
self.embeds.get_or_insert_with(Cow::default).to_mut().extend(embeds);
self
}

Expand All @@ -110,7 +110,7 @@ impl<'a> CreateInteractionResponseFollowup<'a> {
/// Calling this multiple times will overwrite the embed list. To append embeds, call
/// [`Self::add_embeds`] instead.
pub fn embeds(mut self, embeds: impl Into<Cow<'a, [CreateEmbed<'a>]>>) -> Self {
self.embeds = embeds.into();
self.embeds = Some(embeds.into());
self
}

Expand Down
Loading