import type { APIContainerComponent, APIComponentInContainer, } from "discord.js"; import { ComponentType } from "discord.js"; export class V2ContainerBuilder implements APIContainerComponent { id?: number; components: APIComponentInContainer[] = []; accent_color?: number; spoiler?: boolean; readonly type = ComponentType.Container; setId(id: number): this { this.id = id; return this; } setComponents(components: APIComponentInContainer[]): this { if (components.length < 1) throw new Error("Containers must contain at least 1 component."); if (components.length > 10) throw new Error("Container must contain max 10 components."); this.components = components; return this; } setColor(color: number): this { this.accent_color = color; return this; } setSpoiler(spoiler: boolean): this { this.spoiler = spoiler; return this; } toJSON(): APIContainerComponent { return { id: this.id ?? undefined, type: this.type, components: this.components, accent_color: this.accent_color ?? undefined, spoiler: this.spoiler ?? false, }; } } export function makeContainer( components: APIComponentInContainer[], ): V2ContainerBuilder { const builder = new V2ContainerBuilder(); builder.setComponents(components); return builder; }