UNPKG

@discordjs/builders

Version:

A set of builders that you can use when creating your bot

1,485 lines (1,455 loc) • 155 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result; if (kind && result) __defProp(target, key, result); return result; }; // src/index.ts var index_exports = {}; __export(index_exports, { ActionRowBuilder: () => ActionRowBuilder, ApplicationCommandNumericOptionMinMaxValueMixin: () => ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionBase: () => ApplicationCommandOptionBase, ApplicationCommandOptionChannelTypesMixin: () => ApplicationCommandOptionChannelTypesMixin, ApplicationCommandOptionWithAutocompleteMixin: () => ApplicationCommandOptionWithAutocompleteMixin, ApplicationCommandOptionWithChoicesMixin: () => ApplicationCommandOptionWithChoicesMixin, BaseSelectMenuBuilder: () => BaseSelectMenuBuilder, ButtonBuilder: () => ButtonBuilder, ChannelSelectMenuBuilder: () => ChannelSelectMenuBuilder, CheckboxAssertions: () => Assertions_exports3, CheckboxBuilder: () => CheckboxBuilder, CheckboxGroupBuilder: () => CheckboxGroupBuilder, CheckboxGroupOptionBuilder: () => CheckboxGroupOptionBuilder, ComponentAssertions: () => Assertions_exports2, ComponentBuilder: () => ComponentBuilder, ComponentsV2Assertions: () => Assertions_exports8, ContainerBuilder: () => ContainerBuilder, ContextMenuCommandAssertions: () => Assertions_exports11, ContextMenuCommandBuilder: () => ContextMenuCommandBuilder, EmbedAssertions: () => Assertions_exports, EmbedBuilder: () => EmbedBuilder, FileBuilder: () => FileBuilder, FileUploadAssertions: () => Assertions_exports4, FileUploadBuilder: () => FileUploadBuilder, LabelAssertions: () => Assertions_exports7, LabelBuilder: () => LabelBuilder, MediaGalleryBuilder: () => MediaGalleryBuilder, MediaGalleryItemBuilder: () => MediaGalleryItemBuilder, MentionableSelectMenuBuilder: () => MentionableSelectMenuBuilder, ModalAssertions: () => Assertions_exports9, ModalBuilder: () => ModalBuilder, RadioGroupBuilder: () => RadioGroupBuilder, RadioGroupOptionBuilder: () => RadioGroupOptionBuilder, RoleSelectMenuBuilder: () => RoleSelectMenuBuilder, SectionBuilder: () => SectionBuilder, SelectMenuAssertions: () => Assertions_exports6, SelectMenuBuilder: () => StringSelectMenuBuilder, SelectMenuOptionBuilder: () => StringSelectMenuOptionBuilder, SeparatorBuilder: () => SeparatorBuilder, SharedNameAndDescription: () => SharedNameAndDescription, SharedSlashCommand: () => SharedSlashCommand, SharedSlashCommandOptions: () => SharedSlashCommandOptions, SharedSlashCommandSubcommands: () => SharedSlashCommandSubcommands, SlashCommandAssertions: () => Assertions_exports10, SlashCommandAttachmentOption: () => SlashCommandAttachmentOption, SlashCommandBooleanOption: () => SlashCommandBooleanOption, SlashCommandBuilder: () => SlashCommandBuilder, SlashCommandChannelOption: () => SlashCommandChannelOption, SlashCommandIntegerOption: () => SlashCommandIntegerOption, SlashCommandMentionableOption: () => SlashCommandMentionableOption, SlashCommandNumberOption: () => SlashCommandNumberOption, SlashCommandRoleOption: () => SlashCommandRoleOption, SlashCommandStringOption: () => SlashCommandStringOption, SlashCommandSubcommandBuilder: () => SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder: () => SlashCommandSubcommandGroupBuilder, SlashCommandUserOption: () => SlashCommandUserOption, StringSelectMenuBuilder: () => StringSelectMenuBuilder, StringSelectMenuOptionBuilder: () => StringSelectMenuOptionBuilder, TextDisplayBuilder: () => TextDisplayBuilder, TextInputAssertions: () => Assertions_exports5, TextInputBuilder: () => TextInputBuilder, ThumbnailBuilder: () => ThumbnailBuilder, UserSelectMenuBuilder: () => UserSelectMenuBuilder, createComponentBuilder: () => createComponentBuilder, disableValidators: () => disableValidators, embedLength: () => embedLength, enableValidators: () => enableValidators, isValidationEnabled: () => isValidationEnabled, normalizeArray: () => normalizeArray, resolveBuilder: () => resolveBuilder, version: () => version }); module.exports = __toCommonJS(index_exports); // src/messages/embed/Assertions.ts var Assertions_exports = {}; __export(Assertions_exports, { RGBPredicate: () => RGBPredicate, authorNamePredicate: () => authorNamePredicate, colorPredicate: () => colorPredicate, descriptionPredicate: () => descriptionPredicate, embedAuthorPredicate: () => embedAuthorPredicate, embedFieldPredicate: () => embedFieldPredicate, embedFieldsArrayPredicate: () => embedFieldsArrayPredicate, embedFooterPredicate: () => embedFooterPredicate, fieldInlinePredicate: () => fieldInlinePredicate, fieldLengthPredicate: () => fieldLengthPredicate, fieldNamePredicate: () => fieldNamePredicate, fieldValuePredicate: () => fieldValuePredicate, footerTextPredicate: () => footerTextPredicate, imageURLPredicate: () => imageURLPredicate, timestampPredicate: () => timestampPredicate, titlePredicate: () => titlePredicate, urlPredicate: () => urlPredicate, validateFieldLength: () => validateFieldLength }); var import_shapeshift = require("@sapphire/shapeshift"); // src/util/validation.ts var validate = true; function enableValidators() { return validate = true; } __name(enableValidators, "enableValidators"); function disableValidators() { return validate = false; } __name(disableValidators, "disableValidators"); function isValidationEnabled() { return validate; } __name(isValidationEnabled, "isValidationEnabled"); // src/messages/embed/Assertions.ts var fieldNamePredicate = import_shapeshift.s.string().lengthLessThanOrEqual(256).setValidationEnabled(isValidationEnabled); var fieldValuePredicate = import_shapeshift.s.string().lengthLessThanOrEqual(1024).setValidationEnabled(isValidationEnabled); var fieldInlinePredicate = import_shapeshift.s.boolean().optional(); var embedFieldPredicate = import_shapeshift.s.object({ name: fieldNamePredicate, value: fieldValuePredicate, inline: fieldInlinePredicate }).setValidationEnabled(isValidationEnabled); var embedFieldsArrayPredicate = embedFieldPredicate.array().setValidationEnabled(isValidationEnabled); var fieldLengthPredicate = import_shapeshift.s.number().lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); function validateFieldLength(amountAdding, fields) { fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding); } __name(validateFieldLength, "validateFieldLength"); var authorNamePredicate = fieldNamePredicate.lengthGreaterThanOrEqual(1).nullable().setValidationEnabled(isValidationEnabled); var imageURLPredicate = import_shapeshift.s.string().url({ allowedProtocols: ["http:", "https:", "attachment:"] }).nullish().setValidationEnabled(isValidationEnabled); var urlPredicate = import_shapeshift.s.string().url({ allowedProtocols: ["http:", "https:"] }).nullish().setValidationEnabled(isValidationEnabled); var embedAuthorPredicate = import_shapeshift.s.object({ name: authorNamePredicate, iconURL: imageURLPredicate, url: urlPredicate }).setValidationEnabled(isValidationEnabled); var RGBPredicate = import_shapeshift.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(255).setValidationEnabled(isValidationEnabled); var colorPredicate = import_shapeshift.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(16777215).or(import_shapeshift.s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable().setValidationEnabled(isValidationEnabled); var descriptionPredicate = import_shapeshift.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(4096).nullable().setValidationEnabled(isValidationEnabled); var footerTextPredicate = import_shapeshift.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(2048).nullable().setValidationEnabled(isValidationEnabled); var embedFooterPredicate = import_shapeshift.s.object({ text: footerTextPredicate, iconURL: imageURLPredicate }).setValidationEnabled(isValidationEnabled); var timestampPredicate = import_shapeshift.s.union([import_shapeshift.s.number(), import_shapeshift.s.date()]).nullable().setValidationEnabled(isValidationEnabled); var titlePredicate = fieldNamePredicate.lengthGreaterThanOrEqual(1).nullable().setValidationEnabled(isValidationEnabled); // src/util/normalizeArray.ts function normalizeArray(arr) { if (Array.isArray(arr[0])) return [...arr[0]]; return arr; } __name(normalizeArray, "normalizeArray"); // src/messages/embed/Embed.ts var EmbedBuilder = class { static { __name(this, "EmbedBuilder"); } /** * The API data associated with this embed. */ data; /** * Creates a new embed from API data. * * @param data - The API data to create this embed with */ constructor(data = {}) { this.data = { ...data }; if (data.timestamp) this.data.timestamp = new Date(data.timestamp).toISOString(); } /** * Appends fields to the embed. * * @remarks * This method accepts either an array of fields or a variable number of field parameters. * The maximum amount of fields that can be added is 25. * @example * Using an array: * ```ts * const fields: APIEmbedField[] = ...; * const embed = new EmbedBuilder() * .addFields(fields); * ``` * @example * Using rest parameters (variadic): * ```ts * const embed = new EmbedBuilder() * .addFields( * { name: 'Field 1', value: 'Value 1' }, * { name: 'Field 2', value: 'Value 2' }, * ); * ``` * @param fields - The fields to add */ addFields(...fields) { const normalizedFields = normalizeArray(fields); validateFieldLength(normalizedFields.length, this.data.fields); embedFieldsArrayPredicate.parse(normalizedFields); if (this.data.fields) this.data.fields.push(...normalizedFields); else this.data.fields = normalizedFields; return this; } /** * Removes, replaces, or inserts fields for this embed. * * @remarks * This method behaves similarly * to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. * The maximum amount of fields that can be added is 25. * * It's useful for modifying and adjusting order of the already-existing fields of an embed. * @example * Remove the first field: * ```ts * embed.spliceFields(0, 1); * ``` * @example * Remove the first n fields: * ```ts * const n = 4; * embed.spliceFields(0, n); * ``` * @example * Remove the last field: * ```ts * embed.spliceFields(-1, 1); * ``` * @param index - The index to start at * @param deleteCount - The number of fields to remove * @param fields - The replacing field objects */ spliceFields(index, deleteCount, ...fields) { validateFieldLength(fields.length - deleteCount, this.data.fields); embedFieldsArrayPredicate.parse(fields); if (this.data.fields) this.data.fields.splice(index, deleteCount, ...fields); else this.data.fields = fields; return this; } /** * Sets the fields for this embed. * * @remarks * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically, * it splices the entire array of fields, replacing them with the provided fields. * * You can set a maximum of 25 fields. * @param fields - The fields to set */ setFields(...fields) { this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields)); return this; } /** * Sets the author of this embed. * * @param options - The options to use */ setAuthor(options) { if (options === null) { this.data.author = void 0; return this; } embedAuthorPredicate.parse(options); this.data.author = { name: options.name, url: options.url, icon_url: options.iconURL }; return this; } /** * Sets the color of this embed. * * @param color - The color to use */ setColor(color) { colorPredicate.parse(color); if (Array.isArray(color)) { const [red, green, blue] = color; this.data.color = (red << 16) + (green << 8) + blue; return this; } this.data.color = color ?? void 0; return this; } /** * Sets the description of this embed. * * @param description - The description to use */ setDescription(description) { descriptionPredicate.parse(description); this.data.description = description ?? void 0; return this; } /** * Sets the footer of this embed. * * @param options - The footer to use */ setFooter(options) { if (options === null) { this.data.footer = void 0; return this; } embedFooterPredicate.parse(options); this.data.footer = { text: options.text, icon_url: options.iconURL }; return this; } /** * Sets the image of this embed. * * @param url - The image URL to use */ setImage(url) { imageURLPredicate.parse(url); this.data.image = url ? { url } : void 0; return this; } /** * Sets the thumbnail of this embed. * * @param url - The thumbnail URL to use */ setThumbnail(url) { imageURLPredicate.parse(url); this.data.thumbnail = url ? { url } : void 0; return this; } /** * Sets the timestamp of this embed. * * @param timestamp - The timestamp or date to use */ setTimestamp(timestamp = Date.now()) { timestampPredicate.parse(timestamp); this.data.timestamp = timestamp ? new Date(timestamp).toISOString() : void 0; return this; } /** * Sets the title for this embed. * * @param title - The title to use */ setTitle(title) { titlePredicate.parse(title); this.data.title = title ?? void 0; return this; } /** * Sets the URL of this embed. * * @param url - The URL to use */ setURL(url) { urlPredicate.parse(url); this.data.url = url ?? void 0; return this; } /** * Serializes this builder to API-compatible JSON data. * * @remarks * This method runs validations on the data before serializing it. * As such, it may throw an error if the data is invalid. */ toJSON() { return { ...this.data }; } }; // src/index.ts __reExport(index_exports, require("@discordjs/formatters"), module.exports); // src/components/Assertions.ts var Assertions_exports2 = {}; __export(Assertions_exports2, { buttonLabelValidator: () => buttonLabelValidator, buttonStyleValidator: () => buttonStyleValidator, channelTypesValidator: () => channelTypesValidator, customIdValidator: () => customIdValidator, defaultValidator: () => defaultValidator, disabledValidator: () => disabledValidator, emojiValidator: () => emojiValidator, idValidator: () => idValidator, jsonOptionValidator: () => jsonOptionValidator, labelValueDescriptionValidator: () => labelValueDescriptionValidator, minMaxValidator: () => minMaxValidator, optionValidator: () => optionValidator, optionsLengthValidator: () => optionsLengthValidator, optionsValidator: () => optionsValidator, placeholderValidator: () => placeholderValidator, urlValidator: () => urlValidator, validateRequiredButtonParameters: () => validateRequiredButtonParameters, validateRequiredSelectMenuOptionParameters: () => validateRequiredSelectMenuOptionParameters, validateRequiredSelectMenuParameters: () => validateRequiredSelectMenuParameters }); var import_shapeshift2 = require("@sapphire/shapeshift"); var import_v10 = require("discord-api-types/v10"); // src/components/selectMenu/StringSelectMenuOption.ts var StringSelectMenuOptionBuilder = class { /** * Creates a new string select menu option from API data. * * @param data - The API data to create this string select menu option with * @example * Creating a string select menu option from an API data object: * ```ts * const selectMenuOption = new SelectMenuOptionBuilder({ * label: 'catchy label', * value: '1', * }); * ``` * @example * Creating a string select menu option using setters and API data: * ```ts * const selectMenuOption = new SelectMenuOptionBuilder({ * default: true, * value: '1', * }) * .setLabel('woah'); * ``` */ constructor(data = {}) { this.data = data; } static { __name(this, "StringSelectMenuOptionBuilder"); } /** * Sets the label for this option. * * @param label - The label to use */ setLabel(label) { this.data.label = labelValueDescriptionValidator.parse(label); return this; } /** * Sets the value for this option. * * @param value - The value to use */ setValue(value) { this.data.value = labelValueDescriptionValidator.parse(value); return this; } /** * Sets the description for this option. * * @param description - The description to use */ setDescription(description) { this.data.description = labelValueDescriptionValidator.parse(description); return this; } /** * Sets whether this option is selected by default. * * @param isDefault - Whether this option is selected by default */ setDefault(isDefault = true) { this.data.default = defaultValidator.parse(isDefault); return this; } /** * Sets the emoji to display for this option. * * @param emoji - The emoji to use */ setEmoji(emoji) { this.data.emoji = emojiValidator.parse(emoji); return this; } /** * {@inheritDoc BaseSelectMenuBuilder.toJSON} */ toJSON() { validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value); return { ...this.data }; } }; // src/components/Assertions.ts var idValidator = import_shapeshift2.s.number().safeInt().greaterThanOrEqual(1).lessThan(4294967296).setValidationEnabled(isValidationEnabled); var customIdValidator = import_shapeshift2.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); var emojiValidator = import_shapeshift2.s.object({ id: import_shapeshift2.s.string(), name: import_shapeshift2.s.string(), animated: import_shapeshift2.s.boolean() }).partial().strict().setValidationEnabled(isValidationEnabled); var disabledValidator = import_shapeshift2.s.boolean(); var buttonLabelValidator = import_shapeshift2.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(80).setValidationEnabled(isValidationEnabled); var buttonStyleValidator = import_shapeshift2.s.nativeEnum(import_v10.ButtonStyle); var placeholderValidator = import_shapeshift2.s.string().lengthLessThanOrEqual(150).setValidationEnabled(isValidationEnabled); var minMaxValidator = import_shapeshift2.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); var labelValueDescriptionValidator = import_shapeshift2.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); var jsonOptionValidator = import_shapeshift2.s.object({ label: labelValueDescriptionValidator, value: labelValueDescriptionValidator, description: labelValueDescriptionValidator.optional(), emoji: emojiValidator.optional(), default: import_shapeshift2.s.boolean().optional() }).setValidationEnabled(isValidationEnabled); var optionValidator = import_shapeshift2.s.instance(StringSelectMenuOptionBuilder).setValidationEnabled(isValidationEnabled); var optionsValidator = optionValidator.array().lengthGreaterThanOrEqual(0).setValidationEnabled(isValidationEnabled); var optionsLengthValidator = import_shapeshift2.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); function validateRequiredSelectMenuParameters(options, customId) { customIdValidator.parse(customId); optionsValidator.parse(options); } __name(validateRequiredSelectMenuParameters, "validateRequiredSelectMenuParameters"); var defaultValidator = import_shapeshift2.s.boolean(); function validateRequiredSelectMenuOptionParameters(label, value) { labelValueDescriptionValidator.parse(label); labelValueDescriptionValidator.parse(value); } __name(validateRequiredSelectMenuOptionParameters, "validateRequiredSelectMenuOptionParameters"); var channelTypesValidator = import_shapeshift2.s.nativeEnum(import_v10.ChannelType).array().setValidationEnabled(isValidationEnabled); var urlValidator = import_shapeshift2.s.string().url({ allowedProtocols: ["http:", "https:", "discord:"] }).setValidationEnabled(isValidationEnabled); function validateRequiredButtonParameters(style, label, emoji, customId, skuId, url) { if (style === import_v10.ButtonStyle.Premium) { if (!skuId) { throw new RangeError("Premium buttons must have an SKU id."); } if (customId || label || url || emoji) { throw new RangeError("Premium buttons cannot have a custom id, label, URL, or emoji."); } } else { if (skuId) { throw new RangeError("Non-premium buttons must not have an SKU id."); } if (url && customId) { throw new RangeError("URL and custom id are mutually exclusive."); } if (!label && !emoji) { throw new RangeError("Non-premium buttons must have a label and/or an emoji."); } if (style === import_v10.ButtonStyle.Link) { if (!url) { throw new RangeError("Link buttons must have a URL."); } } else if (url) { throw new RangeError("Non-premium and non-link buttons cannot have a URL."); } } } __name(validateRequiredButtonParameters, "validateRequiredButtonParameters"); // src/components/ActionRow.ts var import_v1028 = require("discord-api-types/v10"); // src/components/Component.ts var ComponentBuilder = class { static { __name(this, "ComponentBuilder"); } /** * The API data associated with this component. */ data; /** * Constructs a new kind of component. * * @param data - The data to construct a component out of */ constructor(data) { this.data = data; } /** * Sets the id (not the custom id) for this component. * * @param id - The id for this component */ setId(id) { this.data.id = idValidator.parse(id); return this; } /** * Clears the id of this component, defaulting to a default incremented id. */ clearId() { this.data.id = void 0; return this; } }; // src/components/Components.ts var import_v1027 = require("discord-api-types/v10"); // src/components/button/Button.ts var import_v102 = require("discord-api-types/v10"); var ButtonBuilder = class extends ComponentBuilder { static { __name(this, "ButtonBuilder"); } /** * Creates a new button from API data. * * @param data - The API data to create this button with * @example * Creating a button from an API data object: * ```ts * const button = new ButtonBuilder({ * custom_id: 'a cool button', * style: ButtonStyle.Primary, * label: 'Click Me', * emoji: { * name: 'smile', * id: '123456789012345678', * }, * }); * ``` * @example * Creating a button using setters and API data: * ```ts * const button = new ButtonBuilder({ * style: ButtonStyle.Secondary, * label: 'Click Me', * }) * .setEmoji({ name: '🙂' }) * .setCustomId('another cool button'); * ``` */ constructor(data) { super({ type: import_v102.ComponentType.Button, ...data }); } /** * Sets the style of this button. * * @param style - The style to use */ setStyle(style) { this.data.style = buttonStyleValidator.parse(style); return this; } /** * Sets the URL for this button. * * @remarks * This method is only available to buttons using the `Link` button style. * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`. * @param url - The URL to use */ setURL(url) { this.data.url = urlValidator.parse(url); return this; } /** * Sets the custom id for this button. * * @remarks * This method is only applicable to buttons that are not using the `Link` button style. * @param customId - The custom id to use */ setCustomId(customId) { this.data.custom_id = customIdValidator.parse(customId); return this; } /** * Sets the SKU id that represents a purchasable SKU for this button. * * @remarks Only available when using premium-style buttons. * @param skuId - The SKU id to use */ setSKUId(skuId) { this.data.sku_id = skuId; return this; } /** * Sets the emoji to display on this button. * * @param emoji - The emoji to use */ setEmoji(emoji) { this.data.emoji = emojiValidator.parse(emoji); return this; } /** * Sets whether this button is disabled. * * @param disabled - Whether to disable this button */ setDisabled(disabled = true) { this.data.disabled = disabledValidator.parse(disabled); return this; } /** * Sets the label for this button. * * @param label - The label to use */ setLabel(label) { this.data.label = buttonLabelValidator.parse(label); return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { validateRequiredButtonParameters( this.data.style, this.data.label, this.data.emoji, this.data.custom_id, this.data.sku_id, this.data.url ); return { ...this.data }; } }; // src/components/checkbox/Checkbox.ts var import_v104 = require("discord-api-types/v10"); // src/components/checkbox/Assertions.ts var Assertions_exports3 = {}; __export(Assertions_exports3, { checkboxGroupOptionPredicate: () => checkboxGroupOptionPredicate, checkboxGroupPredicate: () => checkboxGroupPredicate, checkboxPredicate: () => checkboxPredicate, radioGroupOptionPredicate: () => radioGroupOptionPredicate, radioGroupPredicate: () => radioGroupPredicate }); var import_shapeshift3 = require("@sapphire/shapeshift"); var import_v103 = require("discord-api-types/v10"); var checkboxPredicate = import_shapeshift3.s.object({ type: import_shapeshift3.s.literal(import_v103.ComponentType.Checkbox), custom_id: customIdValidator, id: idValidator.optional(), default: import_shapeshift3.s.boolean().optional() }).setValidationEnabled(isValidationEnabled); var checkboxGroupOptionPredicate = import_shapeshift3.s.object({ label: import_shapeshift3.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100), value: import_shapeshift3.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100), description: import_shapeshift3.s.string().lengthLessThanOrEqual(100).optional(), default: import_shapeshift3.s.boolean().optional() }).setValidationEnabled(isValidationEnabled); var checkboxGroupPredicate = import_shapeshift3.s.object({ type: import_shapeshift3.s.literal(import_v103.ComponentType.CheckboxGroup), custom_id: customIdValidator, id: idValidator.optional(), options: import_shapeshift3.s.array(checkboxGroupOptionPredicate).lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(10), min_values: import_shapeshift3.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(10).optional(), max_values: import_shapeshift3.s.number().int().greaterThanOrEqual(1).lessThanOrEqual(10).optional(), required: import_shapeshift3.s.boolean().optional() }).reshape((data) => { if (data.min_values !== void 0 && data.max_values !== void 0 && data.min_values > data.max_values) { return import_shapeshift3.Result.err(new RangeError("min_values cannot be greater than max_values")); } if (data.max_values !== void 0 && data.max_values > data.options.length) { return import_shapeshift3.Result.err(new RangeError("max_values cannot be greater than the number of options")); } if (data.min_values !== void 0 && data.min_values > data.options.length) { return import_shapeshift3.Result.err(new RangeError("min_values cannot be greater than the number of options")); } if (data.required === true && data.min_values === 0) { return import_shapeshift3.Result.err(new RangeError("If required is true, min_values must be at least 1")); } const defaultCount = data.options.filter((option) => option.default === true).length; if (data.max_values !== void 0 && defaultCount > data.max_values) { return import_shapeshift3.Result.err(new RangeError("The number of default options cannot be greater than max_values")); } const values = data.options.map((option) => option.value); const uniqueValues = new Set(values); if (uniqueValues.size !== values.length) { return import_shapeshift3.Result.err(new RangeError("Each option in a checkbox group must have a unique value")); } return import_shapeshift3.Result.ok(data); }).setValidationEnabled(isValidationEnabled); var radioGroupOptionPredicate = checkboxGroupOptionPredicate; var radioGroupPredicate = import_shapeshift3.s.object({ type: import_shapeshift3.s.literal(import_v103.ComponentType.RadioGroup), custom_id: customIdValidator, id: idValidator.optional(), options: import_shapeshift3.s.array(radioGroupOptionPredicate).lengthGreaterThanOrEqual(2).lengthLessThanOrEqual(10), required: import_shapeshift3.s.boolean().optional() }).reshape((data) => { const defaultCount = data.options.filter((option) => option.default === true).length; if (defaultCount > 1) { return import_shapeshift3.Result.err(new RangeError("There can be at most one default option in a radio group")); } const values = data.options.map((option) => option.value); const uniqueValues = new Set(values); if (uniqueValues.size !== values.length) { return import_shapeshift3.Result.err(new RangeError("Each option in a radio group must have a unique value")); } return import_shapeshift3.Result.ok(data); }).setValidationEnabled(isValidationEnabled); // src/components/checkbox/Checkbox.ts var CheckboxBuilder = class extends ComponentBuilder { static { __name(this, "CheckboxBuilder"); } /** * Creates a new checkbox from API data. * * @param data - The API data to create this checkbox with * @example * Creating a checkbox from an API data object: * ```ts * const checkbox = new CheckboxBuilder({ * custom_id: 'accept_terms', * default: false, * }); * ``` * @example * Creating a checkbox using setters and API data: * ```ts * const checkbox = new CheckboxBuilder() * .setCustomId('subscribe_newsletter') * .setDefault(true); * ``` */ constructor(data) { super({ type: import_v104.ComponentType.Checkbox, ...data }); } /** * Sets the custom id of this checkbox. * * @param customId - The custom id to use */ setCustomId(customId) { this.data.custom_id = customId; return this; } /** * Sets whether this checkbox is checked by default. * * @param isDefault - Whether the checkbox should be checked by default */ setDefault(isDefault) { this.data.default = isDefault; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { checkboxPredicate.parse(this.data); return { ...this.data }; } }; // src/components/checkbox/CheckboxGroup.ts var import_v105 = require("discord-api-types/v10"); // src/components/checkbox/CheckboxGroupOption.ts var CheckboxGroupOptionBuilder = class { /** * Creates a new checkbox group option from API data. * * @param data - The API data to create this checkbox group option with * @example * Creating a checkbox group option from an API data object: * ```ts * const option = new CheckboxGroupOptionBuilder({ * label: 'Option 1', * value: 'option_1', * }); * ``` * @example * Creating a checkbox group option using setters and API data: * ```ts * const option = new CheckboxGroupOptionBuilder() * .setLabel('Option 2') * .setValue('option_2'); * ``` */ constructor(data = {}) { this.data = data; } static { __name(this, "CheckboxGroupOptionBuilder"); } /** * Sets the label for this option. * * @param label - The label to use */ setLabel(label) { this.data.label = label; return this; } /** * Sets the value for this option. * * @param value - The value to use */ setValue(value) { this.data.value = value; return this; } /** * Sets the description for this option. * * @param description - The description to use */ setDescription(description) { this.data.description = description; return this; } /** * Sets whether this option is selected by default. * * @param isDefault - Whether the option should be selected by default */ setDefault(isDefault) { this.data.default = isDefault; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { checkboxGroupOptionPredicate.parse(this.data); return { ...this.data }; } }; // src/components/checkbox/CheckboxGroup.ts var CheckboxGroupBuilder = class extends ComponentBuilder { static { __name(this, "CheckboxGroupBuilder"); } /** * The options within this checkbox group. */ options; /** * Creates a new checkbox group from API data. * * @param data - The API data to create this checkbox group with * @example * Creating a checkbox group from an API data object: * ```ts * const checkboxGroup = new CheckboxGroupBuilder({ * custom_id: 'select_options', * options: [ * { label: 'Option 1', value: 'option_1' }, * { label: 'Option 2', value: 'option_2' }, * ], * }); * ``` * @example * Creating a checkbox group using setters and API data: * ```ts * const checkboxGroup = new CheckboxGroupBuilder() * .setCustomId('choose_items') * .setOptions([ * { label: 'Item A', value: 'item_a' }, * { label: 'Item B', value: 'item_b' }, * ]) * .setMinValues(1) * .setMaxValues(2); * ``` */ constructor(data) { const { options, ...initData } = data ?? {}; super({ ...initData, type: import_v105.ComponentType.CheckboxGroup }); this.options = options?.map((option) => new CheckboxGroupOptionBuilder(option)) ?? []; } /** * Sets the custom id of this checkbox group. * * @param customId - The custom id to use */ setCustomId(customId) { this.data.custom_id = customId; return this; } /** * Adds options to this checkbox group. * * @param options - The options to add */ addOptions(...options) { const normalizedOptions = normalizeArray(options); this.options.push( ...normalizedOptions.map((normalizedOption) => { const json = "toJSON" in normalizedOption ? normalizedOption.toJSON() : normalizedOption; const option = new CheckboxGroupOptionBuilder(json); checkboxGroupOptionPredicate.parse(option.toJSON()); return option; }) ); return this; } /** * Sets the options for this checkbox group. * * @param options - The options to use */ setOptions(...options) { return this.spliceOptions(0, this.options.length, ...options); } /** * Removes, replaces, or inserts options for this checkbox group. * * @remarks * This method behaves similarly * to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. * It's useful for modifying and adjusting the order of existing options. * @param index - The index to start at * @param deleteCount - The number of options to remove * @param options - The replacing option objects or builders */ spliceOptions(index, deleteCount, ...options) { const normalizedOptions = normalizeArray(options); const clone = [...this.options]; clone.splice( index, deleteCount, ...normalizedOptions.map((normalizedOption) => { const json = "toJSON" in normalizedOption ? normalizedOption.toJSON() : normalizedOption; const option = new CheckboxGroupOptionBuilder(json); checkboxGroupOptionPredicate.parse(option.toJSON()); return option; }) ); this.options.splice(0, this.options.length, ...clone); return this; } /** * Sets the minimum number of options that must be selected. * * @param minValues - The minimum number of options that must be selected */ setMinValues(minValues) { this.data.min_values = minValues; return this; } /** * Sets the maximum number of options that can be selected. * * @param maxValues - The maximum number of options that can be selected */ setMaxValues(maxValues) { this.data.max_values = maxValues; return this; } /** * Sets whether selecting options is required. * * @param required - Whether selecting options is required */ setRequired(required) { this.data.required = required; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { const data = { ...this.data, options: this.options.map((option) => option.toJSON()) }; checkboxGroupPredicate.parse(data); return data; } }; // src/components/checkbox/RadioGroup.ts var import_v106 = require("discord-api-types/v10"); // src/components/checkbox/RadioGroupOption.ts var RadioGroupOptionBuilder = class { /** * Creates a new radio group option from API data. * * @param data - The API data to create this radio group option with * @example * Creating a radio group option from an API data object: * ```ts * const option = new RadioGroupOptionBuilder({ * label: 'Option 1', * value: 'option_1', * }); * ``` * @example * Creating a radio group option using setters and API data: * ```ts * const option = new RadioGroupOptionBuilder() * .setLabel('Option 2') * .setValue('option_2'); * ``` */ constructor(data = {}) { this.data = data; } static { __name(this, "RadioGroupOptionBuilder"); } /** * Sets the label for this option. * * @param label - The label to use */ setLabel(label) { this.data.label = label; return this; } /** * Sets the value for this option. * * @param value - The value to use */ setValue(value) { this.data.value = value; return this; } /** * Sets the description for this option. * * @param description - The description to use */ setDescription(description) { this.data.description = description; return this; } /** * Sets whether this option is selected by default. * * @param isDefault - Whether the option should be selected by default */ setDefault(isDefault) { this.data.default = isDefault; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { radioGroupOptionPredicate.parse(this.data); return { ...this.data }; } }; // src/components/checkbox/RadioGroup.ts var RadioGroupBuilder = class extends ComponentBuilder { static { __name(this, "RadioGroupBuilder"); } /** * The options within this radio group. */ options; /** * Creates a new radio group from API data. * * @param data - The API data to create this radio group with * @example * Creating a radio group from an API data object: * ```ts * const radioGroup = new RadioGroupBuilder({ * custom_id: 'select_options', * options: [ * { label: 'Option 1', value: 'option_1' }, * { label: 'Option 2', value: 'option_2' }, * ], * }); * ``` * @example * Creating a radio group using setters and API data: * ```ts * const radioGroup = new RadioGroupBuilder() * .setCustomId('choose_items') * .setOptions([ * { label: 'Item A', value: 'item_a' }, * { label: 'Item B', value: 'item_b' }, * ]) * ``` */ constructor(data) { const { options, ...initData } = data ?? {}; super({ ...initData, type: import_v106.ComponentType.RadioGroup }); this.options = options?.map((option) => new RadioGroupOptionBuilder(option)) ?? []; } /** * Sets the custom id of this radio group. * * @param customId - The custom id to use */ setCustomId(customId) { this.data.custom_id = customId; return this; } /** * Adds options to this radio group. * * @param options - The options to add */ addOptions(...options) { const normalizedOptions = normalizeArray(options); this.options.push( ...normalizedOptions.map((normalizedOption) => { const json = "toJSON" in normalizedOption ? normalizedOption.toJSON() : normalizedOption; const option = new RadioGroupOptionBuilder(json); radioGroupOptionPredicate.parse(option.toJSON()); return option; }) ); return this; } /** * Sets the options for this radio group. * * @param options - The options to use */ setOptions(...options) { return this.spliceOptions(0, this.options.length, ...options); } /** * Removes, replaces, or inserts options for this radio group. * * @remarks * This method behaves similarly * to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. * It's useful for modifying and adjusting the order of existing options. * @param index - The index to start at * @param deleteCount - The number of options to remove * @param options - The replacing option objects or builders */ spliceOptions(index, deleteCount, ...options) { const normalizedOptions = normalizeArray(options); const clone = [...this.options]; clone.splice( index, deleteCount, ...normalizedOptions.map((normalizedOption) => { const json = "toJSON" in normalizedOption ? normalizedOption.toJSON() : normalizedOption; const option = new RadioGroupOptionBuilder(json); radioGroupOptionPredicate.parse(option.toJSON()); return option; }) ); this.options.splice(0, this.options.length, ...clone); return this; } /** * Sets whether selecting options is required. * * @param required - Whether selecting options is required */ setRequired(required) { this.data.required = required; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { const data = { ...this.data, options: this.options.map((option) => option.toJSON()) }; radioGroupPredicate.parse(data); return data; } }; // src/components/fileUpload/FileUpload.ts var import_v108 = require("discord-api-types/v10"); // src/components/fileUpload/Assertions.ts var Assertions_exports4 = {}; __export(Assertions_exports4, { fileUploadPredicate: () => fileUploadPredicate }); var import_shapeshift4 = require("@sapphire/shapeshift"); var import_v107 = require("discord-api-types/v10"); var fileUploadPredicate = import_shapeshift4.s.object({ type: import_shapeshift4.s.literal(import_v107.ComponentType.FileUpload), id: idValidator.optional(), custom_id: customIdValidator, min_values: import_shapeshift4.s.number().greaterThanOrEqual(0).lessThanOrEqual(10).optional(), max_values: import_shapeshift4.s.number().greaterThanOrEqual(1).lessThanOrEqual(10).optional(), required: import_shapeshift4.s.boolean().optional() }); // src/components/fileUpload/FileUpload.ts var FileUploadBuilder = class extends ComponentBuilder { static { __name(this, "FileUploadBuilder"); } /** * Creates a new file upload. * * @param data - The API data to create this file upload with * @example * Creating a file upload from an API data object: * ```ts * const fileUpload = new FileUploadBuilder({ * custom_id: "file_upload", * min_values: 2, * max_values: 5, * }); * ``` * @example * Creating a file upload using setters and API data: * ```ts * const fileUpload = new FileUploadBuilder({ * custom_id: "file_upload", * min_values: 2, * max_values: 5, * }).setRequired(); * ``` */ constructor(data = {}) { super({ type: import_v108.ComponentType.FileUpload, ...data }); } /** * Sets the custom id for this file upload. * * @param customId - The custom id to use */ setCustomId(customId) { this.data.custom_id = customId; return this; } /** * Sets the minimum number of file uploads required. * * @param minValues - The minimum values that must be uploaded */ setMinValues(minValues) { this.data.min_values = minValues; return this; } /** * Clears the minimum values. */ clearMinValues() { this.data.min_values = void 0; return this; } /** * Sets the maximum number of file uploads required. * * @param maxValues - The maximum values that can be uploaded */ setMaxValues(maxValues) { this.data.max_values = maxValues; return this; } /** * Clears the maximum values. */ clearMaxValues() { this.data.max_values = void 0; return this; } /** * Sets whether this file upload is required. * * @param required - Whether this file upload is required */ setRequired(required = true) { this.data.required = required; return this; } /** * {@inheritDoc ComponentBuilder.toJSON} */ toJSON() { fileUploadPredicate.parse(this.data); return this.data; } }; // src/components/label/Label.ts var import_v1018 = require("discord-api-types/v10"); // src/components/selectMenu/ChannelSelectMenu.ts var import_v1010 = require("discord-api-types/v10"); // src/components/textInput/Assertions.ts var Assertions_exports5 = {}; __export(Assertions_exports5, { labelValidator: () => labelValidator, maxLengthValidator: () => maxLengthValidator, minLengthValidator: () => minLengthValidator, placeholderValidator: () => placeholderValidator2, requiredValidator: () => requiredValidator, textInputPredicate: () => textInputPredicate, textInputStyleValidator: () => textInputStyleValidator, validateRequiredParameters: () => validateRequiredParameters, valueValidator: () => valueValidator }); var import_shapeshift5 = require("@sapphire/shapeshift"); var import_v109 = require("discord-api-types/v10"); var textInputStyleValidator = import_shapeshift5.s.nativeEnum(import_v109.TextInputStyle).setValidationEnabled(isValidationEnabled); var minLengthValidator = import_shapeshift5.s.number().int().greaterThanOrEqual(0).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); var maxLengthValidator = import_shapeshift5.s.number().int().greaterThanOrEqual(1).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); var requiredValidator = import_shapeshift5.s.boolean().setValidationEnabled(isValidationEnabled); var valueValidator = import_shapeshift5.s.string().lengthLessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); var placeholderValidator2 = import_shapeshift5.s.string().lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); var labelValidator = import_shapeshift5.s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled); var textInputPredicate = import_shapeshift5.s.object({ type: import_shapeshift5.s.literal(import_v109.ComponentType.TextInput), custom_id: customIdValidator, style: textInputStyleValidator, id: idValidator.optional(), min_length: minLengthValidator.optional(), max_length: maxLengthValidator.optional(), placeholder: placeholderValidator2.optional(), value: valueValidator.optional(), required: requiredValidator.optional() }).setValidationEnabled(isValidationEnabled); function validateRequiredParameters(customId, style) { customIdValidator.parse(customId); textInputStyleValidator.parse(style); } __name(validateRequiredParameters, "validateRequiredParameters"); // src/components/selectMenu/BaseSelectMenu.ts var BaseSelectMenuBuilder = class extends ComponentBuilder { static { __name(this, "BaseSelectMenuBuilder"); } /** * Sets the placeholder for this select menu. * * @param placeholder - The placeholder to use */ setPlaceholder(placeholder) {