serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
678 stars 117 forks source link

Reply edit without reset embed #300

Open Morb0 opened 3 months ago

Morb0 commented 3 months ago

Why embeds on reply edit always replaced and not made as allowed_mentions for example? Because of that I can't just edit components without not cloning previous embeds.

https://github.com/serenity-rs/poise/blob/575025909b063c3b998659abf9d241c8790404ee/src/reply/builder.rs#L174-L178

UPD. Okay, I found that for CreateReply field embeds is not Option. Why?

TapGhoul commented 2 months ago

I've found this to be strange too. Though I can see one issue - given existing embeds are kept, there's no way to just clear out all embeds explicitly if this was changed with the current API.

Maybe add

fn embeds(&self, embeds: Vec<serenity::CreateEmbed>) -> Self {
    self.embeds = Some(embeds);
    self
}

that allows the list to be set explicitly? And then replace the existing embed fn with something like

pub fn embed(mut self, embed: serenity::CreateEmbed) -> Self {
    self.embeds.get_or_insert_with(|| Vec::capacity(1)).push(embed);
    self
}

get_or_insert_default() is still nightly only, otherwise I'd suggest that (though the capacity preallocation is a nice to have)