import type { APIMediaGalleryComponent, APIMediaGalleryItem } from "discord.js"; import { ComponentBuilder, ComponentType } from "discord.js"; export class V2MediaGallery extends ComponentBuilder { private id?: number; private items: APIMediaGalleryItem[]; private readonly type = ComponentType.MediaGallery; /** * Create a new media gallery component * @param items - The items to display in the gallery */ constructor(items: APIMediaGalleryItem[]) { super({ type: ComponentType.MediaGallery }); this.items = items; } /** * Set the ID of the media gallery * @param id - The numeric ID * @returns The media gallery instance */ setId(id: number) { this.id = id; return this; } setItems(items: APIMediaGalleryItem[]) { if (items.length < 1) throw new Error("Media gallery must contain at least 1 item"); if (items.length > 10) throw new Error("Media gallery can only contain up to 10 items"); this.items = items; return this; } /** * Convert the media gallery to a JSON object * @returns The JSON representation of the media gallery */ toJSON(): APIMediaGalleryComponent { return { type: this.type, items: this.items, ...(this.id !== undefined && { id: this.id }), }; } } /** * Helper function to create a media gallery component * @param items - The items to display in the gallery * @returns The media gallery instance */ export function makeMediaGallery(items: APIMediaGalleryItem[]): V2MediaGallery { return new V2MediaGallery(items); }