diff --git a/src/reply/builder.rs b/src/reply/builder.rs index 9692c757f1e..5cda021c894 100644 --- a/src/reply/builder.rs +++ b/src/reply/builder.rs @@ -7,7 +7,7 @@ use crate::serenity_prelude as serenity; #[allow(clippy::missing_docs_in_private_items)] // docs on setters pub struct CreateReply { content: Option, - embeds: Vec, + embeds: Option>, attachments: Vec, pub(crate) ephemeral: Option, components: Option>, @@ -30,9 +30,18 @@ impl CreateReply { /// Adds an embed to the message. /// - /// Existing embeds are kept. + /// Existing embeds on this are kept. + /// When editing a message, this will overwrite previously sent embeds. pub fn embed(mut self, embed: serenity::CreateEmbed) -> Self { - self.embeds.push(embed); + self.embeds.get_or_insert_with(Vec::new).push(embed); + self + } + + /// Set embeds for the message. + /// + /// Any previously set embeds will be overwritten. + pub fn embeds(mut self, embeds: Vec) -> Self { + self.embeds = Some(embeds); self } @@ -116,6 +125,9 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } + if let Some(embeds) = embeds { + builder = builder.embeds(embeds); + } if let Some(ephemeral) = ephemeral { builder = builder.ephemeral(ephemeral); } @@ -123,7 +135,7 @@ impl CreateReply { builder = builder.poll(poll); } - builder.add_files(attachments).embeds(embeds) + builder.add_files(attachments) } /// Serialize this response builder to a [`serenity::CreateInteractionResponseFollowup`] @@ -145,10 +157,12 @@ impl CreateReply { if let Some(content) = content { builder = builder.content(content); } - builder = builder.embeds(embeds); if let Some(components) = components { builder = builder.components(components) } + if let Some(embeds) = embeds { + builder = builder.embeds(embeds); + } if let Some(allowed_mentions) = allowed_mentions { builder = builder.allowed_mentions(allowed_mentions); } @@ -185,6 +199,9 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } + if let Some(embeds) = embeds { + builder = builder.embeds(embeds); + } if let Some(allowed_mentions) = allowed_mentions { builder = builder.allowed_mentions(allowed_mentions); } @@ -192,7 +209,7 @@ impl CreateReply { builder = builder.new_attachment(attachment); } - builder.embeds(embeds) + builder } /// Serialize this response builder to a [`serenity::EditMessage`] @@ -223,8 +240,11 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } + if let Some(embeds) = embeds { + builder = builder.embeds(embeds); + } - builder.embeds(embeds).attachments(attachments_builder) + builder.attachments(attachments_builder) } /// Serialize this response builder to a [`serenity::CreateMessage`] @@ -253,6 +273,9 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } + if let Some(embeds) = embeds { + builder = builder.embeds(embeds) + } if reply { builder = builder.reference_message(invocation_message); } @@ -264,6 +287,6 @@ impl CreateReply { builder = builder.add_file(attachment); } - builder.embeds(embeds) + builder } }