MediaGalleryBuilder

export declare class MediaGalleryBuilder extends ComponentBuilder<APIMediaGalleryComponent>
export declare class MediaGalleryBuilder extends ComponentBuilder<APIMediaGalleryComponent>
A builder that creates API-compatible JSON data for a container.
constructor(data?)
Creates a new media gallery from API data.
Example
Creating a media gallery from an API data object:
const mediaGallery = new MediaGalleryBuilder({
items: [
{
description: "Some text here",
media: {
url: 'https://cdn.discordapp.com/embed/avatars/2.png',
},
},
],
});
const mediaGallery = new MediaGalleryBuilder({
items: [
{
description: "Some text here",
media: {
url: 'https://cdn.discordapp.com/embed/avatars/2.png',
},
},
],
});
Example
Creating a media gallery using setters and API data:
const mediaGallery = new MediaGalleryBuilder({
items: [
{
description: "alt text",
media: {
url: 'https://cdn.discordapp.com/embed/avatars/5.png',
},
},
],
})
.addItems(item2, item3);
const mediaGallery = new MediaGalleryBuilder({
items: [
{
description: "alt text",
media: {
url: 'https://cdn.discordapp.com/embed/avatars/5.png',
},
},
],
})
.addItems(item2, item3);
NameTypeOptionalDescription
dataPartial<APIMediaGalleryComponent>YesThe API data to create this media gallery with
The API data associated with this component.
Inherited from ComponentBuilder
Readonly
The components within this container.
addItems(...items):this
Adds items to this media gallery.
NameTypeOptionalDescription
...itemsRestOrArray<APIMediaGalleryItem | MediaGalleryItemBuilder | ((builder: MediaGalleryItemBuilder) => MediaGalleryItemBuilder)>NoThe items to add
clearId():this
Clears the id of this component, defaulting to a default incremented id.
Inherited from ComponentBuilder
setId(id):this
Sets the id (not the custom id) for this component.
NameTypeOptionalDescription
idnumberNoThe id for this component
Inherited from ComponentBuilder
spliceItems(index, deleteCount, ...items):this
Removes, replaces, or inserts media gallery items for this media gallery.
NameTypeOptionalDescription
indexnumberNoThe index to start removing, replacing or inserting items
deleteCountnumberNoThe amount of items to remove
...itemsRestOrArray<APIMediaGalleryItem | MediaGalleryItemBuilder | ((builder: MediaGalleryItemBuilder) => MediaGalleryItemBuilder)>NoThe items to insert
Serializes this builder to API-compatible JSON data.
Remarks
This method runs validations on the data before serializing it. As such, it may throw an error if the data is invalid.