v2componentsbuilder
Version:
A discord.js v2components builder
86 lines (85 loc) • 3.04 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.V2StringSelectBuilder = void 0;
const v10_1 = require("discord-api-types/v10");
class V2StringSelectBuilder {
constructor() {
this.options = [];
}
setCustomId(custom_id) {
if (custom_id.length > 100)
throw new Error("Max length for custom_id is 100 characters");
this.custom_id = custom_id;
return this;
}
setPlaceholder(placeholder) {
if (placeholder.length > 150)
throw new Error("Max length for placeholder is 150 characters");
this.placeholder = placeholder;
return this;
}
setMinValues(min) {
if (min < 0 || min > 25)
throw new Error("min_values must be between 0 and 25");
this.min_values = min;
return this;
}
setMaxValues(max) {
if (max < 1 || max > 25)
throw new Error("max_values must be between 1 and 25");
this.max_values = max;
return this;
}
setDisabled(disabled) {
this.disabled = disabled;
return this;
}
addOption(option) {
if (this.options.length >= 25)
throw new Error("Cannot have more than 25 options");
if (option.label.length > 100)
throw new Error("Label max length is 100 characters");
if (option.value.length > 100)
throw new Error("Value max length is 100 characters");
if (option.description && option.description.length > 100)
throw new Error("Description max length is 100 characters");
this.options.push({
label: option.label,
value: option.value,
description: option.description,
emoji: option.emoji,
default: option.default
});
return this;
}
setOptions(options) {
if (options.length > 25)
throw new Error("Cannot have more than 25 options");
for (const option of options) {
if (option.label.length > 100)
throw new Error("Label max length is 100 characters");
if (option.value.length > 100)
throw new Error("Value max length is 100 characters");
if (option.description && option.description.length > 100)
throw new Error("Description max length is 100 characters");
}
this.options = options;
return this;
}
toJSON() {
if (!this.custom_id)
throw new Error("custom_id is required");
if (this.options.length === 0)
throw new Error("Must have at least one option");
return {
type: v10_1.ComponentType.StringSelect,
custom_id: this.custom_id,
options: this.options,
placeholder: this.placeholder,
min_values: this.min_values,
max_values: this.max_values,
disabled: this.disabled ?? false
};
}
}
exports.V2StringSelectBuilder = V2StringSelectBuilder;