slimp/node_modules/@discordjs/builders/dist/index.js

2562 lines
83 KiB
JavaScript
Raw Normal View History

2023-06-12 11:40:38 -04:00
"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 src_exports = {};
__export(src_exports, {
ActionRowBuilder: () => ActionRowBuilder,
ApplicationCommandNumericOptionMinMaxValueMixin: () => ApplicationCommandNumericOptionMinMaxValueMixin,
ApplicationCommandOptionBase: () => ApplicationCommandOptionBase,
ApplicationCommandOptionChannelTypesMixin: () => ApplicationCommandOptionChannelTypesMixin,
ApplicationCommandOptionWithChoicesAndAutocompleteMixin: () => ApplicationCommandOptionWithChoicesAndAutocompleteMixin,
BaseSelectMenuBuilder: () => BaseSelectMenuBuilder,
ButtonBuilder: () => ButtonBuilder,
ChannelSelectMenuBuilder: () => ChannelSelectMenuBuilder,
ComponentAssertions: () => Assertions_exports2,
ComponentBuilder: () => ComponentBuilder,
ContextMenuCommandAssertions: () => Assertions_exports6,
ContextMenuCommandBuilder: () => ContextMenuCommandBuilder,
EmbedAssertions: () => Assertions_exports,
EmbedBuilder: () => EmbedBuilder,
MentionableSelectMenuBuilder: () => MentionableSelectMenuBuilder,
ModalAssertions: () => Assertions_exports4,
ModalBuilder: () => ModalBuilder,
RoleSelectMenuBuilder: () => RoleSelectMenuBuilder,
SelectMenuBuilder: () => StringSelectMenuBuilder,
SelectMenuOptionBuilder: () => StringSelectMenuOptionBuilder,
SharedNameAndDescription: () => SharedNameAndDescription,
SharedSlashCommandOptions: () => SharedSlashCommandOptions,
SlashCommandAssertions: () => Assertions_exports5,
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,
TextInputAssertions: () => Assertions_exports3,
TextInputBuilder: () => TextInputBuilder,
UserSelectMenuBuilder: () => UserSelectMenuBuilder,
createComponentBuilder: () => createComponentBuilder,
disableValidators: () => disableValidators,
embedLength: () => embedLength,
enableValidators: () => enableValidators,
isValidationEnabled: () => isValidationEnabled,
normalizeArray: () => normalizeArray,
version: () => version
});
module.exports = __toCommonJS(src_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.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(256).setValidationEnabled(isValidationEnabled);
var fieldValuePredicate = import_shapeshift.s.string.lengthGreaterThanOrEqual(1).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.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.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 {
/**
* 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/en-US/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 };
}
};
__name(EmbedBuilder, "EmbedBuilder");
// src/index.ts
__reExport(src_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,
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;
}
/**
* 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
};
}
};
__name(StringSelectMenuOptionBuilder, "StringSelectMenuOptionBuilder");
// src/components/Assertions.ts
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, url) {
if (url && customId) {
throw new RangeError("URL and custom id are mutually exclusive");
}
if (!label && !emoji) {
throw new RangeError("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-link buttons cannot have a url");
}
}
__name(validateRequiredButtonParameters, "validateRequiredButtonParameters");
// src/components/ActionRow.ts
var import_v1011 = require("discord-api-types/v10");
// src/components/Component.ts
var ComponentBuilder = class {
/**
* 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;
}
};
__name(ComponentBuilder, "ComponentBuilder");
// src/components/Components.ts
var import_v1010 = require("discord-api-types/v10");
// src/components/button/Button.ts
var import_v102 = require("discord-api-types/v10");
var ButtonBuilder = class extends ComponentBuilder {
/**
* 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 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.url
);
return {
...this.data
};
}
};
__name(ButtonBuilder, "ButtonBuilder");
// src/components/selectMenu/ChannelSelectMenu.ts
var import_v103 = require("discord-api-types/v10");
// src/components/selectMenu/BaseSelectMenu.ts
var BaseSelectMenuBuilder = class extends ComponentBuilder {
/**
* Sets the placeholder for this select menu.
*
* @param placeholder - The placeholder to use
*/
setPlaceholder(placeholder) {
this.data.placeholder = placeholderValidator.parse(placeholder);
return this;
}
/**
* Sets the minimum values that must be selected in the select menu.
*
* @param minValues - The minimum values that must be selected
*/
setMinValues(minValues) {
this.data.min_values = minMaxValidator.parse(minValues);
return this;
}
/**
* Sets the maximum values that must be selected in the select menu.
*
* @param maxValues - The maximum values that must be selected
*/
setMaxValues(maxValues) {
this.data.max_values = minMaxValidator.parse(maxValues);
return this;
}
/**
* Sets the custom id for this select menu.
*
* @param customId - The custom id to use
*/
setCustomId(customId) {
this.data.custom_id = customIdValidator.parse(customId);
return this;
}
/**
* Sets whether this select menu is disabled.
*
* @param disabled - Whether this select menu is disabled
*/
setDisabled(disabled = true) {
this.data.disabled = disabledValidator.parse(disabled);
return this;
}
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON() {
customIdValidator.parse(this.data.custom_id);
return {
...this.data
};
}
};
__name(BaseSelectMenuBuilder, "BaseSelectMenuBuilder");
// src/components/selectMenu/ChannelSelectMenu.ts
var ChannelSelectMenuBuilder = class extends BaseSelectMenuBuilder {
/**
* Creates a new select menu from API data.
*
* @param data - The API data to create this select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
* const selectMenu = new ChannelSelectMenuBuilder({
* custom_id: 'a cool select menu',
* placeholder: 'select an option',
* max_values: 2,
* });
* ```
* @example
* Creating a select menu using setters and API data:
* ```ts
* const selectMenu = new ChannelSelectMenuBuilder({
* custom_id: 'a cool select menu',
* })
* .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)
* .setMinValues(2);
* ```
*/
constructor(data) {
super({ ...data, type: import_v103.ComponentType.ChannelSelect });
}
/**
* Adds channel types to this select menu.
*
* @param types - The channel types to use
*/
addChannelTypes(...types) {
const normalizedTypes = normalizeArray(types);
this.data.channel_types ??= [];
this.data.channel_types.push(...channelTypesValidator.parse(normalizedTypes));
return this;
}
/**
* Sets channel types for this select menu.
*
* @param types - The channel types to use
*/
setChannelTypes(...types) {
const normalizedTypes = normalizeArray(types);
this.data.channel_types ??= [];
this.data.channel_types.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(normalizedTypes));
return this;
}
/**
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
*/
toJSON() {
customIdValidator.parse(this.data.custom_id);
return {
...this.data
};
}
};
__name(ChannelSelectMenuBuilder, "ChannelSelectMenuBuilder");
// src/components/selectMenu/MentionableSelectMenu.ts
var import_v104 = require("discord-api-types/v10");
var MentionableSelectMenuBuilder = class extends BaseSelectMenuBuilder {
/**
* Creates a new select menu from API data.
*
* @param data - The API data to create this select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
* const selectMenu = new MentionableSelectMenuBuilder({
* custom_id: 'a cool select menu',
* placeholder: 'select an option',
* max_values: 2,
* });
* ```
* @example
* Creating a select menu using setters and API data:
* ```ts
* const selectMenu = new MentionableSelectMenuBuilder({
* custom_id: 'a cool select menu',
* })
* .setMinValues(1);
* ```
*/
constructor(data) {
super({ ...data, type: import_v104.ComponentType.MentionableSelect });
}
};
__name(MentionableSelectMenuBuilder, "MentionableSelectMenuBuilder");
// src/components/selectMenu/RoleSelectMenu.ts
var import_v105 = require("discord-api-types/v10");
var RoleSelectMenuBuilder = class extends BaseSelectMenuBuilder {
/**
* Creates a new select menu from API data.
*
* @param data - The API data to create this select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
* const selectMenu = new RoleSelectMenuBuilder({
* custom_id: 'a cool select menu',
* placeholder: 'select an option',
* max_values: 2,
* });
* ```
* @example
* Creating a select menu using setters and API data:
* ```ts
* const selectMenu = new RoleSelectMenuBuilder({
* custom_id: 'a cool select menu',
* })
* .setMinValues(1);
* ```
*/
constructor(data) {
super({ ...data, type: import_v105.ComponentType.RoleSelect });
}
};
__name(RoleSelectMenuBuilder, "RoleSelectMenuBuilder");
// src/components/selectMenu/StringSelectMenu.ts
var import_v106 = require("discord-api-types/v10");
var StringSelectMenuBuilder = class extends BaseSelectMenuBuilder {
/**
* The options within this select menu.
*/
options;
/**
* Creates a new select menu from API data.
*
* @param data - The API data to create this select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
* const selectMenu = new StringSelectMenuBuilder({
* custom_id: 'a cool select menu',
* placeholder: 'select an option',
* max_values: 2,
* options: [
* { label: 'option 1', value: '1' },
* { label: 'option 2', value: '2' },
* { label: 'option 3', value: '3' },
* ],
* });
* ```
* @example
* Creating a select menu using setters and API data:
* ```ts
* const selectMenu = new StringSelectMenuBuilder({
* custom_id: 'a cool select menu',
* })
* .setMinValues(1)
* .addOptions({
* label: 'Catchy',
* value: 'catch',
* });
* ```
*/
constructor(data) {
const { options, ...initData } = data ?? {};
super({ ...initData, type: import_v106.ComponentType.StringSelect });
this.options = options?.map((option) => new StringSelectMenuOptionBuilder(option)) ?? [];
}
/**
* Adds options to this select menu.
*
* @param options - The options to add
*/
addOptions(...options) {
const normalizedOptions = normalizeArray(options);
optionsLengthValidator.parse(this.options.length + normalizedOptions.length);
this.options.push(
...normalizedOptions.map(
(normalizedOption) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption))
)
);
return this;
}
/**
* Sets the options for this select menu.
*
* @param options - The options to set
*/
setOptions(...options) {
return this.spliceOptions(0, this.options.length, ...options);
}
/**
* Removes, replaces, or inserts options for this select menu.
*
* @remarks
* This method behaves similarly
* to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}.
* It's useful for modifying and adjusting the order of existing options.
* @example
* Remove the first option:
* ```ts
* selectMenu.spliceOptions(0, 1);
* ```
* @example
* Remove the first n option:
* ```ts
* const n = 4;
* selectMenu.spliceOptions(0, n);
* ```
* @example
* Remove the last option:
* ```ts
* selectMenu.spliceOptions(-1, 1);
* ```
* @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) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption))
)
);
optionsLengthValidator.parse(clone.length);
this.options.splice(0, this.options.length, ...clone);
return this;
}
/**
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
*/
toJSON() {
validateRequiredSelectMenuParameters(this.options, this.data.custom_id);
return {
...this.data,
options: this.options.map((option) => option.toJSON())
};
}
};
__name(StringSelectMenuBuilder, "StringSelectMenuBuilder");
// src/components/selectMenu/UserSelectMenu.ts
var import_v107 = require("discord-api-types/v10");
var UserSelectMenuBuilder = class extends BaseSelectMenuBuilder {
/**
* Creates a new select menu from API data.
*
* @param data - The API data to create this select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
* const selectMenu = new UserSelectMenuBuilder({
* custom_id: 'a cool select menu',
* placeholder: 'select an option',
* max_values: 2,
* });
* ```
* @example
* Creating a select menu using setters and API data:
* ```ts
* const selectMenu = new UserSelectMenuBuilder({
* custom_id: 'a cool select menu',
* })
* .setMinValues(1);
* ```
*/
constructor(data) {
super({ ...data, type: import_v107.ComponentType.UserSelect });
}
};
__name(UserSelectMenuBuilder, "UserSelectMenuBuilder");
// src/components/textInput/TextInput.ts
var import_util = require("@discordjs/util");
var import_v109 = require("discord-api-types/v10");
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
// src/components/textInput/Assertions.ts
var Assertions_exports3 = {};
__export(Assertions_exports3, {
labelValidator: () => labelValidator,
maxLengthValidator: () => maxLengthValidator,
minLengthValidator: () => minLengthValidator,
placeholderValidator: () => placeholderValidator2,
requiredValidator: () => requiredValidator,
textInputStyleValidator: () => textInputStyleValidator,
validateRequiredParameters: () => validateRequiredParameters,
valueValidator: () => valueValidator
});
var import_shapeshift3 = require("@sapphire/shapeshift");
var import_v108 = require("discord-api-types/v10");
var textInputStyleValidator = import_shapeshift3.s.nativeEnum(import_v108.TextInputStyle);
var minLengthValidator = import_shapeshift3.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled);
var maxLengthValidator = import_shapeshift3.s.number.int.greaterThanOrEqual(1).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled);
var requiredValidator = import_shapeshift3.s.boolean;
var valueValidator = import_shapeshift3.s.string.lengthLessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled);
var placeholderValidator2 = import_shapeshift3.s.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled);
var labelValidator = import_shapeshift3.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled);
function validateRequiredParameters(customId, style, label) {
customIdValidator.parse(customId);
textInputStyleValidator.parse(style);
labelValidator.parse(label);
}
__name(validateRequiredParameters, "validateRequiredParameters");
// src/components/textInput/TextInput.ts
var TextInputBuilder = class extends ComponentBuilder {
/**
* Creates a new text input from API data.
*
* @param data - The API data to create this text input with
* @example
* Creating a select menu option from an API data object:
* ```ts
* const textInput = new TextInputBuilder({
* custom_id: 'a cool select menu',
* label: 'Type something',
* style: TextInputStyle.Short,
* });
* ```
* @example
* Creating a select menu option using setters and API data:
* ```ts
* const textInput = new TextInputBuilder({
* label: 'Type something else',
* })
* .setCustomId('woah')
* .setStyle(TextInputStyle.Paragraph);
* ```
*/
constructor(data) {
super({ type: import_v109.ComponentType.TextInput, ...data });
}
/**
* Sets the custom id for this text input.
*
* @param customId - The custom id to use
*/
setCustomId(customId) {
this.data.custom_id = customIdValidator.parse(customId);
return this;
}
/**
* Sets the label for this text input.
*
* @param label - The label to use
*/
setLabel(label) {
this.data.label = labelValidator.parse(label);
return this;
}
/**
* Sets the style for this text input.
*
* @param style - The style to use
*/
setStyle(style) {
this.data.style = textInputStyleValidator.parse(style);
return this;
}
/**
* Sets the minimum length of text for this text input.
*
* @param minLength - The minimum length of text for this text input
*/
setMinLength(minLength) {
this.data.min_length = minLengthValidator.parse(minLength);
return this;
}
/**
* Sets the maximum length of text for this text input.
*
* @param maxLength - The maximum length of text for this text input
*/
setMaxLength(maxLength) {
this.data.max_length = maxLengthValidator.parse(maxLength);
return this;
}
/**
* Sets the placeholder for this text input.
*
* @param placeholder - The placeholder to use
*/
setPlaceholder(placeholder) {
this.data.placeholder = placeholderValidator2.parse(placeholder);
return this;
}
/**
* Sets the value for this text input.
*
* @param value - The value to use
*/
setValue(value) {
this.data.value = valueValidator.parse(value);
return this;
}
/**
* Sets whether this text input is required.
*
* @param required - Whether this text input is required
*/
setRequired(required = true) {
this.data.required = requiredValidator.parse(required);
return this;
}
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON() {
validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);
return {
...this.data
};
}
/**
* {@inheritDoc Equatable.equals}
*/
equals(other) {
if ((0, import_util.isJSONEncodable)(other)) {
return (0, import_fast_deep_equal.default)(other.toJSON(), this.data);
}
return (0, import_fast_deep_equal.default)(other, this.data);
}
};
__name(TextInputBuilder, "TextInputBuilder");
// src/components/Components.ts
function createComponentBuilder(data) {
if (data instanceof ComponentBuilder) {
return data;
}
switch (data.type) {
case import_v1010.ComponentType.ActionRow:
return new ActionRowBuilder(data);
case import_v1010.ComponentType.Button:
return new ButtonBuilder(data);
case import_v1010.ComponentType.StringSelect:
return new StringSelectMenuBuilder(data);
case import_v1010.ComponentType.TextInput:
return new TextInputBuilder(data);
case import_v1010.ComponentType.UserSelect:
return new UserSelectMenuBuilder(data);
case import_v1010.ComponentType.RoleSelect:
return new RoleSelectMenuBuilder(data);
case import_v1010.ComponentType.MentionableSelect:
return new MentionableSelectMenuBuilder(data);
case import_v1010.ComponentType.ChannelSelect:
return new ChannelSelectMenuBuilder(data);
default:
throw new Error(`Cannot properly serialize component type: ${data.type}`);
}
}
__name(createComponentBuilder, "createComponentBuilder");
// src/components/ActionRow.ts
var ActionRowBuilder = class extends ComponentBuilder {
/**
* The components within this action row.
*/
components;
/**
* Creates a new action row from API data.
*
* @param data - The API data to create this action row with
* @example
* Creating an action row from an API data object:
* ```ts
* const actionRow = new ActionRowBuilder({
* components: [
* {
* custom_id: "custom id",
* label: "Type something",
* style: TextInputStyle.Short,
* type: ComponentType.TextInput,
* },
* ],
* });
* ```
* @example
* Creating an action row using setters and API data:
* ```ts
* const actionRow = new ActionRowBuilder({
* components: [
* {
* custom_id: "custom id",
* label: "Click me",
* style: ButtonStyle.Primary,
* type: ComponentType.Button,
* },
* ],
* })
* .addComponents(button2, button3);
* ```
*/
constructor({ components, ...data } = {}) {
super({ type: import_v1011.ComponentType.ActionRow, ...data });
this.components = components?.map((component) => createComponentBuilder(component)) ?? [];
}
/**
* Adds components to this action row.
*
* @param components - The components to add
*/
addComponents(...components) {
this.components.push(...normalizeArray(components));
return this;
}
/**
* Sets components for this action row.
*
* @param components - The components to set
*/
setComponents(...components) {
this.components.splice(0, this.components.length, ...normalizeArray(components));
return this;
}
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON() {
return {
...this.data,
components: this.components.map((component) => component.toJSON())
};
}
};
__name(ActionRowBuilder, "ActionRowBuilder");
// src/interactions/modals/Assertions.ts
var Assertions_exports4 = {};
__export(Assertions_exports4, {
componentsValidator: () => componentsValidator,
titleValidator: () => titleValidator,
validateRequiredParameters: () => validateRequiredParameters2
});
var import_shapeshift4 = require("@sapphire/shapeshift");
var titleValidator = import_shapeshift4.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled);
var componentsValidator = import_shapeshift4.s.instance(ActionRowBuilder).array.lengthGreaterThanOrEqual(1).setValidationEnabled(isValidationEnabled);
function validateRequiredParameters2(customId, title, components) {
customIdValidator.parse(customId);
titleValidator.parse(title);
componentsValidator.parse(components);
}
__name(validateRequiredParameters2, "validateRequiredParameters");
// src/interactions/modals/Modal.ts
var ModalBuilder = class {
/**
* The API data associated with this modal.
*/
data;
/**
* The components within this modal.
*/
components = [];
/**
* Creates a new modal from API data.
*
* @param data - The API data to create this modal with
*/
constructor({ components, ...data } = {}) {
this.data = { ...data };
this.components = components?.map((component) => createComponentBuilder(component)) ?? [];
}
/**
* Sets the title of this modal.
*
* @param title - The title to use
*/
setTitle(title) {
this.data.title = titleValidator.parse(title);
return this;
}
/**
* Sets the custom id of this modal.
*
* @param customId - The custom id to use
*/
setCustomId(customId) {
this.data.custom_id = customIdValidator.parse(customId);
return this;
}
/**
* Adds components to this modal.
*
* @param components - The components to add
*/
addComponents(...components) {
this.components.push(
...normalizeArray(components).map(
(component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component)
)
);
return this;
}
/**
* Sets components for this modal.
*
* @param components - The components to set
*/
setComponents(...components) {
this.components.splice(0, this.components.length, ...normalizeArray(components));
return this;
}
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON() {
validateRequiredParameters2(this.data.custom_id, this.data.title, this.components);
return {
...this.data,
components: this.components.map((component) => component.toJSON())
};
}
};
__name(ModalBuilder, "ModalBuilder");
// src/interactions/slashCommands/Assertions.ts
var Assertions_exports5 = {};
__export(Assertions_exports5, {
assertReturnOfBuilder: () => assertReturnOfBuilder,
localizationMapPredicate: () => localizationMapPredicate,
validateChoicesLength: () => validateChoicesLength,
validateDMPermission: () => validateDMPermission,
validateDefaultMemberPermissions: () => validateDefaultMemberPermissions,
validateDefaultPermission: () => validateDefaultPermission,
validateDescription: () => validateDescription,
validateLocale: () => validateLocale,
validateLocalizationMap: () => validateLocalizationMap,
validateMaxOptionsLength: () => validateMaxOptionsLength,
validateNSFW: () => validateNSFW,
validateName: () => validateName,
validateRequired: () => validateRequired,
validateRequiredParameters: () => validateRequiredParameters3
});
var import_shapeshift5 = require("@sapphire/shapeshift");
var import_v1012 = require("discord-api-types/v10");
var namePredicate = import_shapeshift5.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u).setValidationEnabled(isValidationEnabled);
function validateName(name) {
namePredicate.parse(name);
}
__name(validateName, "validateName");
var descriptionPredicate2 = import_shapeshift5.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled);
var localePredicate = import_shapeshift5.s.nativeEnum(import_v1012.Locale);
function validateDescription(description) {
descriptionPredicate2.parse(description);
}
__name(validateDescription, "validateDescription");
var maxArrayLengthPredicate = import_shapeshift5.s.unknown.array.lengthLessThanOrEqual(25).setValidationEnabled(isValidationEnabled);
function validateLocale(locale) {
return localePredicate.parse(locale);
}
__name(validateLocale, "validateLocale");
function validateMaxOptionsLength(options) {
maxArrayLengthPredicate.parse(options);
}
__name(validateMaxOptionsLength, "validateMaxOptionsLength");
function validateRequiredParameters3(name, description, options) {
validateName(name);
validateDescription(description);
validateMaxOptionsLength(options);
}
__name(validateRequiredParameters3, "validateRequiredParameters");
var booleanPredicate = import_shapeshift5.s.boolean;
function validateDefaultPermission(value) {
booleanPredicate.parse(value);
}
__name(validateDefaultPermission, "validateDefaultPermission");
function validateRequired(required) {
booleanPredicate.parse(required);
}
__name(validateRequired, "validateRequired");
var choicesLengthPredicate = import_shapeshift5.s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled);
function validateChoicesLength(amountAdding, choices) {
choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);
}
__name(validateChoicesLength, "validateChoicesLength");
function assertReturnOfBuilder(input, ExpectedInstanceOf) {
import_shapeshift5.s.instance(ExpectedInstanceOf).parse(input);
}
__name(assertReturnOfBuilder, "assertReturnOfBuilder");
var localizationMapPredicate = import_shapeshift5.s.object(Object.fromEntries(Object.values(import_v1012.Locale).map((locale) => [locale, import_shapeshift5.s.string.nullish]))).strict.nullish.setValidationEnabled(isValidationEnabled);
function validateLocalizationMap(value) {
localizationMapPredicate.parse(value);
}
__name(validateLocalizationMap, "validateLocalizationMap");
var dmPermissionPredicate = import_shapeshift5.s.boolean.nullish;
function validateDMPermission(value) {
dmPermissionPredicate.parse(value);
}
__name(validateDMPermission, "validateDMPermission");
var memberPermissionPredicate = import_shapeshift5.s.union(
import_shapeshift5.s.bigint.transform((value) => value.toString()),
import_shapeshift5.s.number.safeInt.transform((value) => value.toString()),
import_shapeshift5.s.string.regex(/^\d+$/)
).nullish;
function validateDefaultMemberPermissions(permissions) {
return memberPermissionPredicate.parse(permissions);
}
__name(validateDefaultMemberPermissions, "validateDefaultMemberPermissions");
function validateNSFW(value) {
booleanPredicate.parse(value);
}
__name(validateNSFW, "validateNSFW");
// src/interactions/slashCommands/SlashCommandBuilder.ts
var import_ts_mixer6 = require("ts-mixer");
// src/interactions/slashCommands/SlashCommandSubcommands.ts
var import_v1024 = require("discord-api-types/v10");
var import_ts_mixer5 = require("ts-mixer");
// src/interactions/slashCommands/mixins/NameAndDescription.ts
var SharedNameAndDescription = class {
/**
* The name of this command.
*/
name;
/**
* The name localizations of this command.
*/
name_localizations;
/**
* The description of this command.
*/
description;
/**
* The description localizations of this command.
*/
description_localizations;
/**
* Sets the name of this command.
*
* @param name - The name to use
*/
setName(name) {
validateName(name);
Reflect.set(this, "name", name);
return this;
}
/**
* Sets the description of this command.
*
* @param description - The description to use
*/
setDescription(description) {
validateDescription(description);
Reflect.set(this, "description", description);
return this;
}
/**
* SSets a name localization for this command.
*
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
setNameLocalization(locale, localizedName) {
if (!this.name_localizations) {
Reflect.set(this, "name_localizations", {});
}
const parsedLocale = validateLocale(locale);
if (localizedName === null) {
this.name_localizations[parsedLocale] = null;
return this;
}
validateName(localizedName);
this.name_localizations[parsedLocale] = localizedName;
return this;
}
/**
* Sets the name localizations for this command.
*
* @param localizedNames - The object of localized names to set
*/
setNameLocalizations(localizedNames) {
if (localizedNames === null) {
Reflect.set(this, "name_localizations", null);
return this;
}
Reflect.set(this, "name_localizations", {});
for (const args of Object.entries(localizedNames)) {
this.setNameLocalization(...args);
}
return this;
}
/**
* Sets a description localization for this command.
*
* @param locale - The locale to set
* @param localizedDescription - The localized description for the given locale
*/
setDescriptionLocalization(locale, localizedDescription) {
if (!this.description_localizations) {
Reflect.set(this, "description_localizations", {});
}
const parsedLocale = validateLocale(locale);
if (localizedDescription === null) {
this.description_localizations[parsedLocale] = null;
return this;
}
validateDescription(localizedDescription);
this.description_localizations[parsedLocale] = localizedDescription;
return this;
}
/**
* Sets the description localizations for this command.
*
* @param localizedDescriptions - The object of localized descriptions to set
*/
setDescriptionLocalizations(localizedDescriptions) {
if (localizedDescriptions === null) {
Reflect.set(this, "description_localizations", null);
return this;
}
Reflect.set(this, "description_localizations", {});
for (const args of Object.entries(localizedDescriptions)) {
this.setDescriptionLocalization(...args);
}
return this;
}
};
__name(SharedNameAndDescription, "SharedNameAndDescription");
// src/interactions/slashCommands/options/attachment.ts
var import_v1013 = require("discord-api-types/v10");
// src/interactions/slashCommands/mixins/ApplicationCommandOptionBase.ts
var ApplicationCommandOptionBase = class extends SharedNameAndDescription {
/**
* Whether this option is required.
*
* @defaultValue `false`
*/
required = false;
/**
* Sets whether this option is required.
*
* @param required - Whether this option should be required
*/
setRequired(required) {
validateRequired(required);
Reflect.set(this, "required", required);
return this;
}
/**
* This method runs required validators on this builder.
*/
runRequiredValidations() {
validateRequiredParameters3(this.name, this.description, []);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
validateRequired(this.required);
}
};
__name(ApplicationCommandOptionBase, "ApplicationCommandOptionBase");
// src/interactions/slashCommands/options/attachment.ts
var SlashCommandAttachmentOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1013.ApplicationCommandOptionType.Attachment;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandAttachmentOption, "SlashCommandAttachmentOption");
// src/interactions/slashCommands/options/boolean.ts
var import_v1014 = require("discord-api-types/v10");
var SlashCommandBooleanOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1014.ApplicationCommandOptionType.Boolean;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandBooleanOption, "SlashCommandBooleanOption");
// src/interactions/slashCommands/options/channel.ts
var import_v1016 = require("discord-api-types/v10");
var import_ts_mixer = require("ts-mixer");
// src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts
var import_shapeshift6 = require("@sapphire/shapeshift");
var import_v1015 = require("discord-api-types/v10");
var allowedChannelTypes = [
import_v1015.ChannelType.GuildText,
import_v1015.ChannelType.GuildVoice,
import_v1015.ChannelType.GuildCategory,
import_v1015.ChannelType.GuildAnnouncement,
import_v1015.ChannelType.AnnouncementThread,
import_v1015.ChannelType.PublicThread,
import_v1015.ChannelType.PrivateThread,
import_v1015.ChannelType.GuildStageVoice,
import_v1015.ChannelType.GuildForum
];
var channelTypesPredicate = import_shapeshift6.s.array(import_shapeshift6.s.union(...allowedChannelTypes.map((type) => import_shapeshift6.s.literal(type))));
var ApplicationCommandOptionChannelTypesMixin = class {
/**
* The channel types of this option.
*/
channel_types;
/**
* Adds channel types to this option.
*
* @param channelTypes - The channel types
*/
addChannelTypes(...channelTypes) {
if (this.channel_types === void 0) {
Reflect.set(this, "channel_types", []);
}
this.channel_types.push(...channelTypesPredicate.parse(channelTypes));
return this;
}
};
__name(ApplicationCommandOptionChannelTypesMixin, "ApplicationCommandOptionChannelTypesMixin");
// src/interactions/slashCommands/options/channel.ts
var SlashCommandChannelOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1016.ApplicationCommandOptionType.Channel;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandChannelOption, "SlashCommandChannelOption");
SlashCommandChannelOption = __decorateClass([
(0, import_ts_mixer.mix)(ApplicationCommandOptionChannelTypesMixin)
], SlashCommandChannelOption);
// src/interactions/slashCommands/options/integer.ts
var import_shapeshift8 = require("@sapphire/shapeshift");
var import_v1018 = require("discord-api-types/v10");
var import_ts_mixer2 = require("ts-mixer");
// src/interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts
var ApplicationCommandNumericOptionMinMaxValueMixin = class {
/**
* The maximum value of this option.
*/
max_value;
/**
* The minimum value of this option.
*/
min_value;
};
__name(ApplicationCommandNumericOptionMinMaxValueMixin, "ApplicationCommandNumericOptionMinMaxValueMixin");
// src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts
var import_shapeshift7 = require("@sapphire/shapeshift");
var import_v1017 = require("discord-api-types/v10");
var stringPredicate = import_shapeshift7.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);
var numberPredicate = import_shapeshift7.s.number.greaterThan(Number.NEGATIVE_INFINITY).lessThan(Number.POSITIVE_INFINITY);
var choicesPredicate = import_shapeshift7.s.object({
name: stringPredicate,
name_localizations: localizationMapPredicate,
value: import_shapeshift7.s.union(stringPredicate, numberPredicate)
}).array;
var booleanPredicate2 = import_shapeshift7.s.boolean;
var ApplicationCommandOptionWithChoicesAndAutocompleteMixin = class {
/**
* The choices of this option.
*/
choices;
/**
* Whether this option utilizes autocomplete.
*/
autocomplete;
/**
* The type of this option.
*
* @privateRemarks Since this is present and this is a mixin, this is needed.
*/
type;
/**
* Adds multiple choices to this option.
*
* @param choices - The choices to add
*/
addChoices(...choices) {
if (choices.length > 0 && this.autocomplete) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
choicesPredicate.parse(choices);
if (this.choices === void 0) {
Reflect.set(this, "choices", []);
}
validateChoicesLength(choices.length, this.choices);
for (const { name, name_localizations, value } of choices) {
if (this.type === import_v1017.ApplicationCommandOptionType.String) {
stringPredicate.parse(value);
} else {
numberPredicate.parse(value);
}
this.choices.push({ name, name_localizations, value });
}
return this;
}
/**
* Sets multiple choices for this option.
*
* @param choices - The choices to set
*/
setChoices(...choices) {
if (choices.length > 0 && this.autocomplete) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
choicesPredicate.parse(choices);
Reflect.set(this, "choices", []);
this.addChoices(...choices);
return this;
}
/**
* Whether this option uses autocomplete.
*
* @param autocomplete - Whether this option should use autocomplete
*/
setAutocomplete(autocomplete) {
booleanPredicate2.parse(autocomplete);
if (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
Reflect.set(this, "autocomplete", autocomplete);
return this;
}
};
__name(ApplicationCommandOptionWithChoicesAndAutocompleteMixin, "ApplicationCommandOptionWithChoicesAndAutocompleteMixin");
// src/interactions/slashCommands/options/integer.ts
var numberValidator = import_shapeshift8.s.number.int;
var SlashCommandIntegerOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1018.ApplicationCommandOptionType.Integer;
/**
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
*/
setMaxValue(max) {
numberValidator.parse(max);
Reflect.set(this, "max_value", max);
return this;
}
/**
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
*/
setMinValue(min) {
numberValidator.parse(min);
Reflect.set(this, "min_value", min);
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
return { ...this };
}
};
__name(SlashCommandIntegerOption, "SlashCommandIntegerOption");
SlashCommandIntegerOption = __decorateClass([
(0, import_ts_mixer2.mix)(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
], SlashCommandIntegerOption);
// src/interactions/slashCommands/options/mentionable.ts
var import_v1019 = require("discord-api-types/v10");
var SlashCommandMentionableOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1019.ApplicationCommandOptionType.Mentionable;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandMentionableOption, "SlashCommandMentionableOption");
// src/interactions/slashCommands/options/number.ts
var import_shapeshift9 = require("@sapphire/shapeshift");
var import_v1020 = require("discord-api-types/v10");
var import_ts_mixer3 = require("ts-mixer");
var numberValidator2 = import_shapeshift9.s.number;
var SlashCommandNumberOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1020.ApplicationCommandOptionType.Number;
/**
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
*/
setMaxValue(max) {
numberValidator2.parse(max);
Reflect.set(this, "max_value", max);
return this;
}
/**
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
*/
setMinValue(min) {
numberValidator2.parse(min);
Reflect.set(this, "min_value", min);
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
return { ...this };
}
};
__name(SlashCommandNumberOption, "SlashCommandNumberOption");
SlashCommandNumberOption = __decorateClass([
(0, import_ts_mixer3.mix)(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
], SlashCommandNumberOption);
// src/interactions/slashCommands/options/role.ts
var import_v1021 = require("discord-api-types/v10");
var SlashCommandRoleOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1021.ApplicationCommandOptionType.Role;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandRoleOption, "SlashCommandRoleOption");
// src/interactions/slashCommands/options/string.ts
var import_shapeshift10 = require("@sapphire/shapeshift");
var import_v1022 = require("discord-api-types/v10");
var import_ts_mixer4 = require("ts-mixer");
var minLengthValidator2 = import_shapeshift10.s.number.greaterThanOrEqual(0).lessThanOrEqual(6e3);
var maxLengthValidator2 = import_shapeshift10.s.number.greaterThanOrEqual(1).lessThanOrEqual(6e3);
var SlashCommandStringOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1022.ApplicationCommandOptionType.String;
/**
* The maximum length of this option.
*/
max_length;
/**
* The minimum length of this option.
*/
min_length;
/**
* Sets the maximum length of this string option.
*
* @param max - The maximum length this option can be
*/
setMaxLength(max) {
maxLengthValidator2.parse(max);
Reflect.set(this, "max_length", max);
return this;
}
/**
* Sets the minimum length of this string option.
*
* @param min - The minimum length this option can be
*/
setMinLength(min) {
minLengthValidator2.parse(min);
Reflect.set(this, "min_length", min);
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
throw new RangeError("Autocomplete and choices are mutually exclusive to each other.");
}
return { ...this };
}
};
__name(SlashCommandStringOption, "SlashCommandStringOption");
SlashCommandStringOption = __decorateClass([
(0, import_ts_mixer4.mix)(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
], SlashCommandStringOption);
// src/interactions/slashCommands/options/user.ts
var import_v1023 = require("discord-api-types/v10");
var SlashCommandUserOption = class extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
type = import_v1023.ApplicationCommandOptionType.User;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
toJSON() {
this.runRequiredValidations();
return { ...this };
}
};
__name(SlashCommandUserOption, "SlashCommandUserOption");
// src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts
var SharedSlashCommandOptions = class {
options;
/**
* Adds a boolean option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addBooleanOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandBooleanOption);
}
/**
* Adds a user option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addUserOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandUserOption);
}
/**
* Adds a channel option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addChannelOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandChannelOption);
}
/**
* Adds a role option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addRoleOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandRoleOption);
}
/**
* Adds an attachment option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addAttachmentOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption);
}
/**
* Adds a mentionable option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addMentionableOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandMentionableOption);
}
/**
* Adds a string option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addStringOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandStringOption);
}
/**
* Adds an integer option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addIntegerOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandIntegerOption);
}
/**
* Adds a number option.
*
* @param input - A function that returns an option builder or an already built builder
*/
addNumberOption(input) {
return this._sharedAddOptionMethod(input, SlashCommandNumberOption);
}
/**
* Where the actual adding magic happens.
*
* @param input - The input. What else?
* @param Instance - The instance of whatever is being added
* @internal
*/
_sharedAddOptionMethod(input, Instance) {
const { options } = this;
validateMaxOptionsLength(options);
const result = typeof input === "function" ? input(new Instance()) : input;
assertReturnOfBuilder(result, Instance);
options.push(result);
return this;
}
};
__name(SharedSlashCommandOptions, "SharedSlashCommandOptions");
// src/interactions/slashCommands/SlashCommandSubcommands.ts
var SlashCommandSubcommandGroupBuilder = class {
/**
* The name of this subcommand group.
*/
name = void 0;
/**
* The description of this subcommand group.
*/
description = void 0;
/**
* The subcommands within this subcommand group.
*/
options = [];
/**
* Adds a new subcommand to this group.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input) {
const { options } = this;
validateMaxOptionsLength(options);
const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input;
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
options.push(result);
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() {
validateRequiredParameters3(this.name, this.description, this.options);
return {
type: import_v1024.ApplicationCommandOptionType.SubcommandGroup,
name: this.name,
name_localizations: this.name_localizations,
description: this.description,
description_localizations: this.description_localizations,
options: this.options.map((option) => option.toJSON())
};
}
};
__name(SlashCommandSubcommandGroupBuilder, "SlashCommandSubcommandGroupBuilder");
SlashCommandSubcommandGroupBuilder = __decorateClass([
(0, import_ts_mixer5.mix)(SharedNameAndDescription)
], SlashCommandSubcommandGroupBuilder);
var SlashCommandSubcommandBuilder = class {
/**
* The name of this subcommand.
*/
name = void 0;
/**
* The description of this subcommand.
*/
description = void 0;
/**
* The options within this subcommand.
*/
options = [];
/**
* 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() {
validateRequiredParameters3(this.name, this.description, this.options);
return {
type: import_v1024.ApplicationCommandOptionType.Subcommand,
name: this.name,
name_localizations: this.name_localizations,
description: this.description,
description_localizations: this.description_localizations,
options: this.options.map((option) => option.toJSON())
};
}
};
__name(SlashCommandSubcommandBuilder, "SlashCommandSubcommandBuilder");
SlashCommandSubcommandBuilder = __decorateClass([
(0, import_ts_mixer5.mix)(SharedNameAndDescription, SharedSlashCommandOptions)
], SlashCommandSubcommandBuilder);
// src/interactions/slashCommands/SlashCommandBuilder.ts
var SlashCommandBuilder = class {
/**
* The name of this command.
*/
name = void 0;
/**
* The name localizations of this command.
*/
name_localizations;
/**
* The description of this command.
*/
description = void 0;
/**
* The description localizations of this command.
*/
description_localizations;
/**
* The options of this command.
*/
options = [];
/**
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
default_permission = void 0;
/**
* The set of permissions represented as a bit set for the command.
*/
default_member_permissions = void 0;
/**
* Indicates whether the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This property is only for global commands.
*/
dm_permission = void 0;
/**
* Whether this command is NSFW.
*/
nsfw = void 0;
/**
* Sets whether the command is enabled by default when the application is added to a guild.
*
* @remarks
* If set to `false`, you will have to later `PUT` the permissions for this command.
* @param value - Whether or not to enable this command by default
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
* @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead.
*/
setDefaultPermission(value) {
validateDefaultPermission(value);
Reflect.set(this, "default_permission", value);
return this;
}
/**
* Sets the default permissions a member should have in order to run the command.
*
* @remarks
* You can set this to `'0'` to disable the command by default.
* @param permissions - The permissions bit field to set
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
setDefaultMemberPermissions(permissions) {
const permissionValue = validateDefaultMemberPermissions(permissions);
Reflect.set(this, "default_member_permissions", permissionValue);
return this;
}
/**
* Sets if the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This method is only for global commands.
* @param enabled - Whether the command should be enabled in direct messages
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
setDMPermission(enabled) {
validateDMPermission(enabled);
Reflect.set(this, "dm_permission", enabled);
return this;
}
/**
* Sets whether this command is NSFW.
*
* @param nsfw - Whether this command is NSFW
*/
setNSFW(nsfw = true) {
validateNSFW(nsfw);
Reflect.set(this, "nsfw", nsfw);
return this;
}
/**
* Adds a new subcommand group to this command.
*
* @param input - A function that returns a subcommand group builder or an already built builder
*/
addSubcommandGroup(input) {
const { options } = this;
validateMaxOptionsLength(options);
const result = typeof input === "function" ? input(new SlashCommandSubcommandGroupBuilder()) : input;
assertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder);
options.push(result);
return this;
}
/**
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder or an already built builder
*/
addSubcommand(input) {
const { options } = this;
validateMaxOptionsLength(options);
const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input;
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
options.push(result);
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() {
validateRequiredParameters3(this.name, this.description, this.options);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
return {
...this,
options: this.options.map((option) => option.toJSON())
};
}
};
__name(SlashCommandBuilder, "SlashCommandBuilder");
SlashCommandBuilder = __decorateClass([
(0, import_ts_mixer6.mix)(SharedSlashCommandOptions, SharedNameAndDescription)
], SlashCommandBuilder);
// src/interactions/contextMenuCommands/Assertions.ts
var Assertions_exports6 = {};
__export(Assertions_exports6, {
validateDMPermission: () => validateDMPermission2,
validateDefaultMemberPermissions: () => validateDefaultMemberPermissions2,
validateDefaultPermission: () => validateDefaultPermission2,
validateName: () => validateName2,
validateRequiredParameters: () => validateRequiredParameters4,
validateType: () => validateType
});
var import_shapeshift11 = require("@sapphire/shapeshift");
var import_v1025 = require("discord-api-types/v10");
var namePredicate2 = import_shapeshift11.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^( *[\p{P}\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}]+ *)+$/u).setValidationEnabled(isValidationEnabled);
var typePredicate = import_shapeshift11.s.union(import_shapeshift11.s.literal(import_v1025.ApplicationCommandType.User), import_shapeshift11.s.literal(import_v1025.ApplicationCommandType.Message)).setValidationEnabled(isValidationEnabled);
var booleanPredicate3 = import_shapeshift11.s.boolean;
function validateDefaultPermission2(value) {
booleanPredicate3.parse(value);
}
__name(validateDefaultPermission2, "validateDefaultPermission");
function validateName2(name) {
namePredicate2.parse(name);
}
__name(validateName2, "validateName");
function validateType(type) {
typePredicate.parse(type);
}
__name(validateType, "validateType");
function validateRequiredParameters4(name, type) {
validateName2(name);
validateType(type);
}
__name(validateRequiredParameters4, "validateRequiredParameters");
var dmPermissionPredicate2 = import_shapeshift11.s.boolean.nullish;
function validateDMPermission2(value) {
dmPermissionPredicate2.parse(value);
}
__name(validateDMPermission2, "validateDMPermission");
var memberPermissionPredicate2 = import_shapeshift11.s.union(
import_shapeshift11.s.bigint.transform((value) => value.toString()),
import_shapeshift11.s.number.safeInt.transform((value) => value.toString()),
import_shapeshift11.s.string.regex(/^\d+$/)
).nullish;
function validateDefaultMemberPermissions2(permissions) {
return memberPermissionPredicate2.parse(permissions);
}
__name(validateDefaultMemberPermissions2, "validateDefaultMemberPermissions");
// src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts
var ContextMenuCommandBuilder = class {
/**
* The name of this command.
*/
name = void 0;
/**
* The name localizations of this command.
*/
name_localizations;
/**
* The type of this command.
*/
type = void 0;
/**
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
default_permission = void 0;
/**
* The set of permissions represented as a bit set for the command.
*/
default_member_permissions = void 0;
/**
* Indicates whether the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This property is only for global commands.
*/
dm_permission = void 0;
/**
* Sets the name of this command.
*
* @param name - The name to use
*/
setName(name) {
validateName2(name);
Reflect.set(this, "name", name);
return this;
}
/**
* Sets the type of this command.
*
* @param type - The type to use
*/
setType(type) {
validateType(type);
Reflect.set(this, "type", type);
return this;
}
/**
* Sets whether the command is enabled by default when the application is added to a guild.
*
* @remarks
* If set to `false`, you will have to later `PUT` the permissions for this command.
* @param value - Whether to enable this command by default
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
setDefaultPermission(value) {
validateDefaultPermission2(value);
Reflect.set(this, "default_permission", value);
return this;
}
/**
* Sets the default permissions a member should have in order to run this command.
*
* @remarks
* You can set this to `'0'` to disable the command by default.
* @param permissions - The permissions bit field to set
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
setDefaultMemberPermissions(permissions) {
const permissionValue = validateDefaultMemberPermissions2(permissions);
Reflect.set(this, "default_member_permissions", permissionValue);
return this;
}
/**
* Sets if the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This method is only for global commands.
* @param enabled - Whether the command should be enabled in direct messages
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
setDMPermission(enabled) {
validateDMPermission2(enabled);
Reflect.set(this, "dm_permission", enabled);
return this;
}
/**
* Sets a name localization for this command.
*
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
setNameLocalization(locale, localizedName) {
if (!this.name_localizations) {
Reflect.set(this, "name_localizations", {});
}
const parsedLocale = validateLocale(locale);
if (localizedName === null) {
this.name_localizations[parsedLocale] = null;
return this;
}
validateName2(localizedName);
this.name_localizations[parsedLocale] = localizedName;
return this;
}
/**
* Sets the name localizations for this command.
*
* @param localizedNames - The object of localized names to set
*/
setNameLocalizations(localizedNames) {
if (localizedNames === null) {
Reflect.set(this, "name_localizations", null);
return this;
}
Reflect.set(this, "name_localizations", {});
for (const args of Object.entries(localizedNames))
this.setNameLocalization(...args);
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() {
validateRequiredParameters4(this.name, this.type);
validateLocalizationMap(this.name_localizations);
return { ...this };
}
};
__name(ContextMenuCommandBuilder, "ContextMenuCommandBuilder");
// src/util/componentUtil.ts
function embedLength(data) {
return (data.title?.length ?? 0) + (data.description?.length ?? 0) + (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) + (data.footer?.text.length ?? 0) + (data.author?.name.length ?? 0);
}
__name(embedLength, "embedLength");
// src/index.ts
var version = "1.6.3";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ActionRowBuilder,
ApplicationCommandNumericOptionMinMaxValueMixin,
ApplicationCommandOptionBase,
ApplicationCommandOptionChannelTypesMixin,
ApplicationCommandOptionWithChoicesAndAutocompleteMixin,
BaseSelectMenuBuilder,
ButtonBuilder,
ChannelSelectMenuBuilder,
ComponentAssertions,
ComponentBuilder,
ContextMenuCommandAssertions,
ContextMenuCommandBuilder,
EmbedAssertions,
EmbedBuilder,
MentionableSelectMenuBuilder,
ModalAssertions,
ModalBuilder,
RoleSelectMenuBuilder,
SelectMenuBuilder,
SelectMenuOptionBuilder,
SharedNameAndDescription,
SharedSlashCommandOptions,
SlashCommandAssertions,
SlashCommandAttachmentOption,
SlashCommandBooleanOption,
SlashCommandBuilder,
SlashCommandChannelOption,
SlashCommandIntegerOption,
SlashCommandMentionableOption,
SlashCommandNumberOption,
SlashCommandRoleOption,
SlashCommandStringOption,
SlashCommandSubcommandBuilder,
SlashCommandSubcommandGroupBuilder,
SlashCommandUserOption,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
TextInputAssertions,
TextInputBuilder,
UserSelectMenuBuilder,
createComponentBuilder,
disableValidators,
embedLength,
enableValidators,
isValidationEnabled,
normalizeArray,
version,
...require("@discordjs/formatters")
});
//# sourceMappingURL=index.js.map