pub struct ContainerBuilder { /* private fields */ }Expand description
Builds a container: a box around 1-40 components with an optional accent color, like an embed made of components.
It holds action rows, text displays (or text), sections, media galleries,
separators and files (D-198, D-204); build checks the mix, each child, the
accent color (at most 0xFFFFFF) and that custom_ids inside are unique.
discord.js counterpart: ContainerBuilder.
§Examples
use djs_builders::{
ActionRowBuilder, ButtonBuilder, ContainerBuilder, MediaGalleryBuilder, SectionBuilder,
SeparatorBuilder, ThumbnailBuilder,
};
let card = ContainerBuilder::new()
.accent_color(0x58_65F2)
.text("## New release")
.component(
SectionBuilder::new(ThumbnailBuilder::new("attachment://logo.png"))
.text("djs-rs 0.1 is out")
.text("-# November 12"),
)
.component(SeparatorBuilder::new())
.component(MediaGalleryBuilder::new().item("https://example.com/a.png"))
.component(
ActionRowBuilder::new()
.component(ButtonBuilder::link("https://example.com").label("Download")),
)
.build()?;
assert_eq!(card.children().len(), 5);Implementations§
Source§impl ContainerBuilder
impl ContainerBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty container; it needs 1-40 components.
discord.js counterpart: new ContainerBuilder().
Sourcepub fn text(self, content: impl Into<CompactString>) -> Self
pub fn text(self, content: impl Into<CompactString>) -> Self
Adds a text display showing content (markdown, 1-4000 characters).
discord.js counterpart: addTextDisplayComponents.
Sourcepub fn component(self, component: impl Into<Component>) -> Self
pub fn component(self, component: impl Into<Component>) -> Self
Adds a component after those already added: an action row, text display, section,
media gallery, separator or file — a builder of this crate or a djs-model
[Component].
discord.js counterpart: addActionRowComponents, addSectionComponents, … (one per
type).
Sourcepub fn components<C: Into<Component>>(
self,
components: impl IntoIterator<Item = C>,
) -> Self
pub fn components<C: Into<Component>>( self, components: impl IntoIterator<Item = C>, ) -> Self
Adds several components.
discord.js counterpart: ContainerBuilder#addTextDisplayComponents and its siblings.
Sourcepub fn accent_color(self, color: u32) -> Self
pub fn accent_color(self, color: u32) -> Self
Sets the color of the left border as an RGB integer (0xRRGGBB, at most 0xFFFFFF).
discord.js counterpart: setAccentColor.
Source§impl ContainerBuilder
impl ContainerBuilder
Sourcepub fn id(self, id: i32) -> Self
pub fn id(self, id: i32) -> Self
Sets the component’s numeric identifier (Discord generates one otherwise); it must be unique in the message or modal.
discord.js counterpart: setId.
Sourcepub fn build(self) -> Result<Component, ValidationError>
pub fn build(self) -> Result<Component, ValidationError>
Checks the component (and what it contains) and returns it.
discord.js counterpart: toJSON of the component builders.
§Errors
The first ValidationError found; see the type docs
for the rules.
Sourcepub fn build_unchecked(self) -> Component
pub fn build_unchecked(self) -> Component
Returns the component without any check (D-180).
discord.js counterpart: toJSON of the component builders with validation off (disableValidators).