UNPKG

v2componentsbuilder

Version:
47 lines (46 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.V2SectionBuilder = void 0; const v10_1 = require("discord-api-types/v10"); const ACCESSORY_TYPES = [ v10_1.ComponentType.Button, v10_1.ComponentType.StringSelect, v10_1.ComponentType.UserSelect, v10_1.ComponentType.RoleSelect, v10_1.ComponentType.MentionableSelect, v10_1.ComponentType.ChannelSelect, v10_1.ComponentType.Thumbnail, ]; class V2SectionBuilder { constructor() { this.type = v10_1.ComponentType.Section; } setId(id) { this.id = id; return this; } setComponents(components) { if (components.length < 1 || components.length > 3) throw new Error('Sections must contain between 1 and 3 text display components.'); this.components = components.map(c => c.toJSON()); return this; } setAccessory(component) { component = component.toJSON(); if (!ACCESSORY_TYPES.includes(component.type)) { throw new Error(`Invalid accessory type ${component.type}. ` + `Must be one of: ${ACCESSORY_TYPES.join(', ')}.`); } this.accessory = component; return this; } toJSON() { return { id: this.id ?? undefined, type: v10_1.ComponentType.Section, components: this.components, accessory: this.accessory, }; } } exports.V2SectionBuilder = V2SectionBuilder;