Components & Interactions
addMediaGallery
$addMediaGallery[] — Media Gallery
$addMediaGallery[] starts a Components V2 media gallery: a block that shows several images together. Images are added with $addMediaGalleryItem[].
Syntax
$addMediaGallery[(id);(containerId)]
Parameters
| Parameter | Required | Description |
|---|---|---|
id |
No | Identifier used to target this gallery from the galleryId argument of $addMediaGalleryItem[]. It is not sent to Discord. |
containerId |
No | Name of a container defined earlier: the gallery goes in it. A name that does not exist raises Container <name> not found. In a script that names nothing, the gallery goes into the latest $addContainer. |
Return value
Returns an empty string. The gallery is created empty.
Behavior
- Items are added with
$addMediaGalleryItem[], which targets the last gallery unless agalleryIdis given. - The gallery ends a section being built with
$addSection. - The engine does not check that the gallery has items, nor their number.
Components V2 rules
- Layout components (
$addContainer,$addSection,$addSeparator,$addTextDisplay,$addMediaGallery,$addThumbnail,$addFile) make the response a Components V2 message. Such a message cannot carry content or embeds: the text written in the script and the embed functions are not sent. - Buttons and select menus (
$addButtonCV2,$addStringSelect, …) can be added after any layout component: they go in an action row. - A Components V2 message holds at most 40 components and a gallery 1 to 10 items (
A media gallery holds 1 to 10 items.).
Examples
Simple gallery
$addMediaGallery[portfolio]
$addMediaGalleryItem[https://cdn.example.com/work1.png;Project 1]
$addMediaGalleryItem[https://cdn.example.com/work2.png;Project 2]
$addMediaGalleryItem[https://cdn.example.com/work3.png;Project 3]
Gallery in a container
$addContainer[showcase;#E67E22]
$addTextDisplay[**Creation Gallery**]
$addMediaGallery[creations]
$addMediaGalleryItem[https://cdn.example.com/a.png;Original]
$addMediaGalleryItem[https://cdn.example.com/b.png;Variant]
Gallery with spoiler images
$addMediaGallery[spoiler_gallery]
$addMediaGalleryItem[https://cdn.example.com/secret.png;Exclusive content;yes]
$addMediaGalleryItem[https://cdn.example.com/bonus.png;Bonus;yes]
Notes
- Gallery elements are added using
$addMediaGalleryItem[]. - Embeds (
$title,$description, …) cannot be combined with a gallery: a Components V2 message carries no embed.
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.