pub struct MediaGalleryBuilder { /* private fields */ }Expand description
Builds a media gallery: a grid of 1-10 images and videos.
Add plain items with item and items with alt text or a spoiler with
item_with (D-204). Each URL is a link or an uploaded file.
discord.js counterpart: MediaGalleryBuilder.
§Examples
use djs_builders::{MediaGalleryBuilder, MediaGalleryItemBuilder};
let gallery = MediaGalleryBuilder::new()
.item("https://example.com/a.png")
.item_with(MediaGalleryItemBuilder::new("attachment://b.png").description("A chart").spoiler(true))
.build()
.unwrap();
assert_eq!(gallery.kind(), djs_model::component::ComponentType::MediaGallery);Implementations§
Source§impl MediaGalleryBuilder
impl MediaGalleryBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty gallery; it needs 1-10 items.
discord.js counterpart: new MediaGalleryBuilder().
Sourcepub fn item(self, url: impl Into<CompactString>) -> Self
pub fn item(self, url: impl Into<CompactString>) -> Self
Adds an item showing url.
discord.js counterpart: addItems.
Sourcepub fn item_with(self, item: MediaGalleryItemBuilder) -> Self
pub fn item_with(self, item: MediaGalleryItemBuilder) -> Self
Adds an item with alt text or a spoiler.
discord.js counterpart: addItems(new MediaGalleryItemBuilder()…).
Sourcepub fn items<I: Into<MediaGalleryItem>>(
self,
items: impl IntoIterator<Item = I>,
) -> Self
pub fn items<I: Into<MediaGalleryItem>>( self, items: impl IntoIterator<Item = I>, ) -> Self
Adds several items: MediaGalleryItemBuilders or djs-model
[MediaGalleryItem]s.
discord.js counterpart: addItems.
Source§impl MediaGalleryBuilder
impl MediaGalleryBuilder
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).