UNPKG

v2componentsbuilder

Version:
34 lines (33 loc) 933 B
import { ComponentType } from 'discord-api-types/v10'; export class V2ContainerBuilder { constructor() { this.type = ComponentType.Container; } setId(id) { this.id = id; return this; } setComponents(components) { if (components.length < 1 || components.length > 10) throw new Error('Containers must contain between 1 and 10 components.'); this.components = components.map(c => c.toJSON()); return this; } setColor(color) { this.accent_color = color; return this; } setSpoiler(spoiler) { this.spoiler = spoiler; return this; } toJSON() { return { id: this.id ?? undefined, type: ComponentType.Container, components: this.components, accent_color: this.accent_color ?? undefined, spoiler: this.spoiler ?? false, }; } }