@discordjs/builders
Version:
A set of builders that you can use when creating your bot
1,376 lines (1,353 loc) • 600 kB
text/typescript
import * as _sapphire_shapeshift from '@sapphire/shapeshift';
import { APIEmbedField, APIEmbedAuthor, APIEmbed, APIEmbedFooter, APIEmbedImage, APISelectMenuOption, APIMessageComponentEmoji, ButtonStyle, ChannelType, APIBaseComponent, ComponentType, APIActionRowComponent, APIComponentInActionRow, APIMessageComponent, APIModalComponent, APIButtonComponent, Snowflake, APISelectMenuComponent, APIChannelSelectComponent, APIMentionableSelectComponent, APISelectMenuDefaultValue, SelectMenuDefaultValueType, APIRoleSelectComponent, APIStringSelectComponent, APIUserSelectComponent, APITextInputComponent, TextInputStyle, APIComponentInMessageActionRow, APIComponentInModalActionRow, APICheckboxComponent, APICheckboxGroupOption, APICheckboxGroupComponent, APIRadioGroupOption, APIRadioGroupComponent, APIFileUploadComponent, APILabelComponent, APIFileComponent, APISeparatorComponent, SeparatorSpacingSize, APITextDisplayComponent, APIContainerComponent, APIMediaGalleryComponent, APISectionComponent, APIComponentInContainer, APIMediaGalleryItem, APIThumbnailComponent, APIModalInteractionResponseCallbackData, LocalizationMap, LocaleString, InteractionContextType, Permissions, ApplicationIntegrationType, RESTPostAPIChatInputApplicationCommandsJSONBody, ApplicationCommandOptionType, APIApplicationCommandBasicOption, APIApplicationCommandAttachmentOption, APIApplicationCommandBooleanOption, APIApplicationCommandChannelOption, APIApplicationCommandOptionChoice, APIApplicationCommandIntegerOption, APIApplicationCommandMentionableOption, APIApplicationCommandNumberOption, APIApplicationCommandRoleOption, APIApplicationCommandStringOption, APIApplicationCommandUserOption, APIApplicationCommandSubcommandOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandOption, Locale, ApplicationCommandType, RESTPostAPIContextMenuApplicationCommandsJSONBody } from 'discord-api-types/v10';
export * from '@discordjs/formatters';
import { JSONEncodable, Equatable } from '@discordjs/util';
declare const fieldNamePredicate: _sapphire_shapeshift.StringValidator<string>;
declare const fieldValuePredicate: _sapphire_shapeshift.StringValidator<string>;
declare const fieldInlinePredicate: _sapphire_shapeshift.UnionValidator<boolean | undefined>;
declare const embedFieldPredicate: _sapphire_shapeshift.ObjectValidator<{
name: string;
value: string;
inline: boolean | undefined;
}, _sapphire_shapeshift.UndefinedToOptional<{
name: string;
value: string;
inline: boolean | undefined;
}>>;
declare const embedFieldsArrayPredicate: _sapphire_shapeshift.ArrayValidator<_sapphire_shapeshift.UndefinedToOptional<{
name: string;
value: string;
inline: boolean | undefined;
}>[], _sapphire_shapeshift.UndefinedToOptional<{
name: string;
value: string;
inline: boolean | undefined;
}>>;
declare const fieldLengthPredicate: _sapphire_shapeshift.NumberValidator<number>;
declare function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void;
declare const authorNamePredicate: _sapphire_shapeshift.UnionValidator<string | null>;
declare const imageURLPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>;
declare const urlPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>;
declare const embedAuthorPredicate: _sapphire_shapeshift.ObjectValidator<{
name: string | null;
iconURL: string | null | undefined;
url: string | null | undefined;
}, _sapphire_shapeshift.UndefinedToOptional<{
name: string | null;
iconURL: string | null | undefined;
url: string | null | undefined;
}>>;
declare const RGBPredicate: _sapphire_shapeshift.NumberValidator<number>;
declare const colorPredicate: _sapphire_shapeshift.UnionValidator<number | [number, number, number] | null>;
declare const descriptionPredicate$1: _sapphire_shapeshift.UnionValidator<string | null>;
declare const footerTextPredicate: _sapphire_shapeshift.UnionValidator<string | null>;
declare const embedFooterPredicate: _sapphire_shapeshift.ObjectValidator<{
text: string | null;
iconURL: string | null | undefined;
}, _sapphire_shapeshift.UndefinedToOptional<{
text: string | null;
iconURL: string | null | undefined;
}>>;
declare const timestampPredicate: _sapphire_shapeshift.UnionValidator<number | Date | null>;
declare const titlePredicate: _sapphire_shapeshift.UnionValidator<string | null>;
declare const Assertions$a_RGBPredicate: typeof RGBPredicate;
declare const Assertions$a_authorNamePredicate: typeof authorNamePredicate;
declare const Assertions$a_colorPredicate: typeof colorPredicate;
declare const Assertions$a_embedAuthorPredicate: typeof embedAuthorPredicate;
declare const Assertions$a_embedFieldPredicate: typeof embedFieldPredicate;
declare const Assertions$a_embedFieldsArrayPredicate: typeof embedFieldsArrayPredicate;
declare const Assertions$a_embedFooterPredicate: typeof embedFooterPredicate;
declare const Assertions$a_fieldInlinePredicate: typeof fieldInlinePredicate;
declare const Assertions$a_fieldLengthPredicate: typeof fieldLengthPredicate;
declare const Assertions$a_fieldNamePredicate: typeof fieldNamePredicate;
declare const Assertions$a_fieldValuePredicate: typeof fieldValuePredicate;
declare const Assertions$a_footerTextPredicate: typeof footerTextPredicate;
declare const Assertions$a_imageURLPredicate: typeof imageURLPredicate;
declare const Assertions$a_timestampPredicate: typeof timestampPredicate;
declare const Assertions$a_titlePredicate: typeof titlePredicate;
declare const Assertions$a_urlPredicate: typeof urlPredicate;
declare const Assertions$a_validateFieldLength: typeof validateFieldLength;
declare namespace Assertions$a {
export { Assertions$a_RGBPredicate as RGBPredicate, Assertions$a_authorNamePredicate as authorNamePredicate, Assertions$a_colorPredicate as colorPredicate, descriptionPredicate$1 as descriptionPredicate, Assertions$a_embedAuthorPredicate as embedAuthorPredicate, Assertions$a_embedFieldPredicate as embedFieldPredicate, Assertions$a_embedFieldsArrayPredicate as embedFieldsArrayPredicate, Assertions$a_embedFooterPredicate as embedFooterPredicate, Assertions$a_fieldInlinePredicate as fieldInlinePredicate, Assertions$a_fieldLengthPredicate as fieldLengthPredicate, Assertions$a_fieldNamePredicate as fieldNamePredicate, Assertions$a_fieldValuePredicate as fieldValuePredicate, Assertions$a_footerTextPredicate as footerTextPredicate, Assertions$a_imageURLPredicate as imageURLPredicate, Assertions$a_timestampPredicate as timestampPredicate, Assertions$a_titlePredicate as titlePredicate, Assertions$a_urlPredicate as urlPredicate, Assertions$a_validateFieldLength as validateFieldLength };
}
/**
* Normalizes data that is a rest parameter or an array into an array with a depth of 1.
*
* @typeParam ItemType - The data that must satisfy {@link RestOrArray}.
* @param arr - The (possibly variadic) data to normalize
*/
declare function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[];
/**
* Represents data that may be an array or came from a rest parameter.
*
* @remarks
* This type is used throughout builders to ensure both an array and variadic arguments
* may be used. It is normalized with {@link normalizeArray}.
*/
type RestOrArray<Type> = Type[] | [Type[]];
/**
* A tuple satisfying the RGB color model.
*
* @see {@link https://developer.mozilla.org/docs/Glossary/RGB}
*/
type RGBTuple = [red: number, green: number, blue: number];
/**
* The base icon data typically used in payloads.
*/
interface IconData {
/**
* The URL of the icon.
*/
iconURL?: string;
/**
* The proxy URL of the icon.
*/
proxyIconURL?: string;
}
/**
* Represents the author data of an embed.
*/
interface EmbedAuthorData extends IconData, Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'> {
}
/**
* Represents the author options of an embed.
*/
interface EmbedAuthorOptions extends Omit<EmbedAuthorData, 'proxyIconURL'> {
}
/**
* Represents the footer data of an embed.
*/
interface EmbedFooterData extends IconData, Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'> {
}
/**
* Represents the footer options of an embed.
*/
interface EmbedFooterOptions extends Omit<EmbedFooterData, 'proxyIconURL'> {
}
/**
* Represents the image data of an embed.
*/
interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {
/**
* The proxy URL for the image.
*/
proxyURL?: string;
}
/**
* A builder that creates API-compatible JSON data for embeds.
*/
declare class EmbedBuilder {
/**
* The API data associated with this embed.
*/
readonly data: APIEmbed;
/**
* Creates a new embed from API data.
*
* @param data - The API data to create this embed with
*/
constructor(data?: APIEmbed);
/**
* 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: RestOrArray<APIEmbedField>): 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: number, deleteCount: number, ...fields: APIEmbedField[]): 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: RestOrArray<APIEmbedField>): this;
/**
* Sets the author of this embed.
*
* @param options - The options to use
*/
setAuthor(options: EmbedAuthorOptions | null): this;
/**
* Sets the color of this embed.
*
* @param color - The color to use
*/
setColor(color: RGBTuple | number | null): this;
/**
* Sets the description of this embed.
*
* @param description - The description to use
*/
setDescription(description: string | null): this;
/**
* Sets the footer of this embed.
*
* @param options - The footer to use
*/
setFooter(options: EmbedFooterOptions | null): this;
/**
* Sets the image of this embed.
*
* @param url - The image URL to use
*/
setImage(url: string | null): this;
/**
* Sets the thumbnail of this embed.
*
* @param url - The thumbnail URL to use
*/
setThumbnail(url: string | null): this;
/**
* Sets the timestamp of this embed.
*
* @param timestamp - The timestamp or date to use
*/
setTimestamp(timestamp?: Date | number | null): this;
/**
* Sets the title for this embed.
*
* @param title - The title to use
*/
setTitle(title: string | null): this;
/**
* Sets the URL of this embed.
*
* @param url - The URL to use
*/
setURL(url: string | null): 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(): APIEmbed;
}
/**
* A builder that creates API-compatible JSON data for string select menu options.
*/
declare class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
data: Partial<APISelectMenuOption>;
/**
* 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?: Partial<APISelectMenuOption>);
/**
* Sets the label for this option.
*
* @param label - The label to use
*/
setLabel(label: string): this;
/**
* Sets the value for this option.
*
* @param value - The value to use
*/
setValue(value: string): this;
/**
* Sets the description for this option.
*
* @param description - The description to use
*/
setDescription(description: string): this;
/**
* Sets whether this option is selected by default.
*
* @param isDefault - Whether this option is selected by default
*/
setDefault(isDefault?: boolean): this;
/**
* Sets the emoji to display for this option.
*
* @param emoji - The emoji to use
*/
setEmoji(emoji: APIMessageComponentEmoji): this;
/**
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
*/
toJSON(): APISelectMenuOption;
}
declare const idValidator: _sapphire_shapeshift.NumberValidator<number>;
declare const customIdValidator: _sapphire_shapeshift.StringValidator<string>;
declare const emojiValidator: _sapphire_shapeshift.ObjectValidator<{
name?: string | undefined;
id?: string | undefined;
animated?: boolean | undefined;
}, _sapphire_shapeshift.UndefinedToOptional<{
name?: string | undefined;
id?: string | undefined;
animated?: boolean | undefined;
}>>;
declare const disabledValidator: _sapphire_shapeshift.BooleanValidator<boolean>;
declare const buttonLabelValidator: _sapphire_shapeshift.StringValidator<string>;
declare const buttonStyleValidator: _sapphire_shapeshift.NativeEnumValidator<typeof ButtonStyle>;
declare const placeholderValidator$1: _sapphire_shapeshift.StringValidator<string>;
declare const minMaxValidator: _sapphire_shapeshift.NumberValidator<number>;
declare const labelValueDescriptionValidator: _sapphire_shapeshift.StringValidator<string>;
/**
* @deprecated Replaced with selectMenuStringOptionPredicate.
*/
declare const jsonOptionValidator: _sapphire_shapeshift.ObjectValidator<{
label: string;
value: string;
description: string | undefined;
emoji: _sapphire_shapeshift.UndefinedToOptional<{
name?: string | undefined;
id?: string | undefined;
animated?: boolean | undefined;
}> | undefined;
default: boolean | undefined;
}, _sapphire_shapeshift.UndefinedToOptional<{
label: string;
value: string;
description: string | undefined;
emoji: _sapphire_shapeshift.UndefinedToOptional<{
name?: string | undefined;
id?: string | undefined;
animated?: boolean | undefined;
}> | undefined;
default: boolean | undefined;
}>>;
declare const optionValidator: _sapphire_shapeshift.InstanceValidator<StringSelectMenuOptionBuilder>;
declare const optionsValidator: _sapphire_shapeshift.ArrayValidator<StringSelectMenuOptionBuilder[], StringSelectMenuOptionBuilder>;
declare const optionsLengthValidator: _sapphire_shapeshift.NumberValidator<number>;
declare function validateRequiredSelectMenuParameters(options: StringSelectMenuOptionBuilder[], customId?: string): void;
declare const defaultValidator: _sapphire_shapeshift.BooleanValidator<boolean>;
declare function validateRequiredSelectMenuOptionParameters(label?: string, value?: string): void;
declare const channelTypesValidator: _sapphire_shapeshift.ArrayValidator<ChannelType[], ChannelType>;
declare const urlValidator: _sapphire_shapeshift.StringValidator<string>;
declare function validateRequiredButtonParameters(style?: ButtonStyle, label?: string, emoji?: APIMessageComponentEmoji, customId?: string, skuId?: string, url?: string): void;
declare const Assertions$9_buttonLabelValidator: typeof buttonLabelValidator;
declare const Assertions$9_buttonStyleValidator: typeof buttonStyleValidator;
declare const Assertions$9_channelTypesValidator: typeof channelTypesValidator;
declare const Assertions$9_customIdValidator: typeof customIdValidator;
declare const Assertions$9_defaultValidator: typeof defaultValidator;
declare const Assertions$9_disabledValidator: typeof disabledValidator;
declare const Assertions$9_emojiValidator: typeof emojiValidator;
declare const Assertions$9_idValidator: typeof idValidator;
declare const Assertions$9_jsonOptionValidator: typeof jsonOptionValidator;
declare const Assertions$9_labelValueDescriptionValidator: typeof labelValueDescriptionValidator;
declare const Assertions$9_minMaxValidator: typeof minMaxValidator;
declare const Assertions$9_optionValidator: typeof optionValidator;
declare const Assertions$9_optionsLengthValidator: typeof optionsLengthValidator;
declare const Assertions$9_optionsValidator: typeof optionsValidator;
declare const Assertions$9_urlValidator: typeof urlValidator;
declare const Assertions$9_validateRequiredButtonParameters: typeof validateRequiredButtonParameters;
declare const Assertions$9_validateRequiredSelectMenuOptionParameters: typeof validateRequiredSelectMenuOptionParameters;
declare const Assertions$9_validateRequiredSelectMenuParameters: typeof validateRequiredSelectMenuParameters;
declare namespace Assertions$9 {
export { Assertions$9_buttonLabelValidator as buttonLabelValidator, Assertions$9_buttonStyleValidator as buttonStyleValidator, Assertions$9_channelTypesValidator as channelTypesValidator, Assertions$9_customIdValidator as customIdValidator, Assertions$9_defaultValidator as defaultValidator, Assertions$9_disabledValidator as disabledValidator, Assertions$9_emojiValidator as emojiValidator, Assertions$9_idValidator as idValidator, Assertions$9_jsonOptionValidator as jsonOptionValidator, Assertions$9_labelValueDescriptionValidator as labelValueDescriptionValidator, Assertions$9_minMaxValidator as minMaxValidator, Assertions$9_optionValidator as optionValidator, Assertions$9_optionsLengthValidator as optionsLengthValidator, Assertions$9_optionsValidator as optionsValidator, placeholderValidator$1 as placeholderValidator, Assertions$9_urlValidator as urlValidator, Assertions$9_validateRequiredButtonParameters as validateRequiredButtonParameters, Assertions$9_validateRequiredSelectMenuOptionParameters as validateRequiredSelectMenuOptionParameters, Assertions$9_validateRequiredSelectMenuParameters as validateRequiredSelectMenuParameters };
}
/**
* Any action row component data represented as an object.
*/
type AnyAPIActionRowComponent = APIActionRowComponent<APIComponentInActionRow> | APIComponentInActionRow | APIMessageComponent | APIModalComponent;
/**
* The base component builder that contains common symbols for all sorts of components.
*
* @typeParam DataType - The type of internal API data that is stored within the component
*/
declare abstract class ComponentBuilder<DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>> implements JSONEncodable<AnyAPIActionRowComponent> {
/**
* The API data associated with this component.
*/
readonly data: Partial<DataType>;
/**
* 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.
*/
abstract toJSON(): AnyAPIActionRowComponent;
/**
* Constructs a new kind of component.
*
* @param data - The data to construct a component out of
*/
constructor(data: Partial<DataType>);
/**
* Sets the id (not the custom id) for this component.
*
* @param id - The id for this component
*/
setId(id: number): this;
/**
* Clears the id of this component, defaulting to a default incremented id.
*/
clearId(): this;
}
/**
* A builder that creates API-compatible JSON data for buttons.
*/
declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
/**
* 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?: Partial<APIButtonComponent>);
/**
* Sets the style of this button.
*
* @param style - The style to use
*/
setStyle(style: ButtonStyle): 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: string): 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: string): 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: Snowflake): this;
/**
* Sets the emoji to display on this button.
*
* @param emoji - The emoji to use
*/
setEmoji(emoji: APIMessageComponentEmoji): this;
/**
* Sets whether this button is disabled.
*
* @param disabled - Whether to disable this button
*/
setDisabled(disabled?: boolean): this;
/**
* Sets the label for this button.
*
* @param label - The label to use
*/
setLabel(label: string): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APIButtonComponent;
}
/**
* The base select menu builder that contains common symbols for select menu builders.
*
* @typeParam SelectMenuType - The type of select menu this would be instantiated for.
*/
declare abstract class BaseSelectMenuBuilder<SelectMenuType extends APISelectMenuComponent> extends ComponentBuilder<SelectMenuType> {
/**
* Sets the placeholder for this select menu.
*
* @param placeholder - The placeholder to use
*/
setPlaceholder(placeholder: string): this;
/**
* Sets the minimum values that must be selected in the select menu.
*
* @param minValues - The minimum values that must be selected
*/
setMinValues(minValues: number): this;
/**
* Sets the maximum values that can be selected in the select menu.
*
* @param maxValues - The maximum values that can be selected
*/
setMaxValues(maxValues: number): this;
/**
* Sets the custom id for this select menu.
*
* @param customId - The custom id to use
*/
setCustomId(customId: string): this;
/**
* Sets whether this select menu is disabled.
*
* @param disabled - Whether this select menu is disabled
*/
setDisabled(disabled?: boolean): this;
/**
* Sets whether this select menu is required.
*
* @remarks Only for use in modals.
* @param required - Whether this select menu is required
*/
setRequired(required?: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): SelectMenuType;
}
/**
* A builder that creates API-compatible JSON data for channel select menus.
*/
declare class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSelectComponent> {
/**
* 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?: Partial<APIChannelSelectComponent>);
/**
* Adds channel types to this select menu.
*
* @param types - The channel types to use
*/
addChannelTypes(...types: RestOrArray<ChannelType>): this;
/**
* Sets channel types for this select menu.
*
* @param types - The channel types to use
*/
setChannelTypes(...types: RestOrArray<ChannelType>): this;
/**
* Adds default channels to this auto populated select menu.
*
* @param channels - The channels to add
*/
addDefaultChannels(...channels: RestOrArray<Snowflake>): this;
/**
* Sets default channels for this auto populated select menu.
*
* @param channels - The channels to set
*/
setDefaultChannels(...channels: RestOrArray<Snowflake>): this;
/**
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
*/
toJSON(): APIChannelSelectComponent;
}
/**
* A builder that creates API-compatible JSON data for mentionable select menus.
*/
declare class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMentionableSelectComponent> {
/**
* 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?: Partial<APIMentionableSelectComponent>);
/**
* Adds default roles to this auto populated select menu.
*
* @param roles - The roles to add
*/
addDefaultRoles(...roles: RestOrArray<Snowflake>): this;
/**
* Adds default users to this auto populated select menu.
*
* @param users - The users to add
*/
addDefaultUsers(...users: RestOrArray<Snowflake>): this;
/**
* Adds default values to this auto populated select menu.
*
* @param values - The values to add
*/
addDefaultValues(...values: RestOrArray<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role> | APISelectMenuDefaultValue<SelectMenuDefaultValueType.User>>): this;
/**
* Sets default values for this auto populated select menu.
*
* @param values - The values to set
*/
setDefaultValues(...values: RestOrArray<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role> | APISelectMenuDefaultValue<SelectMenuDefaultValueType.User>>): this;
}
/**
* A builder that creates API-compatible JSON data for role select menus.
*/
declare class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectComponent> {
/**
* 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?: Partial<APIRoleSelectComponent>);
/**
* Adds default roles to this auto populated select menu.
*
* @param roles - The roles to add
*/
addDefaultRoles(...roles: RestOrArray<Snowflake>): this;
/**
* Sets default roles for this auto populated select menu.
*
* @param roles - The roles to set
*/
setDefaultRoles(...roles: RestOrArray<Snowflake>): this;
}
/**
* A builder that creates API-compatible JSON data for string select menus.
*/
declare class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSelectComponent> {
/**
* The options within this select menu.
*/
readonly options: StringSelectMenuOptionBuilder[];
/**
* 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?: Partial<APIStringSelectComponent>);
/**
* Adds options to this select menu.
*
* @param options - The options to add
*/
addOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this;
/**
* Sets the options for this select menu.
*
* @param options - The options to set
*/
setOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this;
/**
* Removes, replaces, or inserts options for this select menu.
*
* @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.
* @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: number, deleteCount: number, ...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this;
/**
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
*/
toJSON(): APIStringSelectComponent;
}
/**
* A builder that creates API-compatible JSON data for user select menus.
*/
declare class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectComponent> {
/**
* 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?: Partial<APIUserSelectComponent>);
/**
* Adds default users to this auto populated select menu.
*
* @param users - The users to add
*/
addDefaultUsers(...users: RestOrArray<Snowflake>): this;
/**
* Sets default users for this auto populated select menu.
*
* @param users - The users to set
*/
setDefaultUsers(...users: RestOrArray<Snowflake>): this;
}
/**
* A builder that creates API-compatible JSON data for text inputs.
*/
declare class TextInputBuilder extends ComponentBuilder<APITextInputComponent> implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>> {
/**
* Creates a new text input from API data.
*
* @param data - The API data to create this text input with
* @example
* Creating a text input from an API data object:
* ```ts
* const textInput = new TextInputBuilder({
* custom_id: 'a cool text input',
* placeholder: 'Type something',
* style: TextInputStyle.Short,
* });
* ```
* @example
* Creating a text input using setters and API data:
* ```ts
* const textInput = new TextInputBuilder({
* placeholder: 'Type something else',
* })
* .setCustomId('woah')
* .setStyle(TextInputStyle.Paragraph);
* ```
*/
constructor(data?: APITextInputComponent & {
type?: ComponentType.TextInput;
});
/**
* Sets the custom id for this text input.
*
* @param customId - The custom id to use
*/
setCustomId(customId: string): this;
/**
* Sets the label for this text input.
*
* @param label - The label to use
* @deprecated Use a label builder to create a label (and optionally a description) instead.
*/
setLabel(label: string): this;
/**
* Sets the style for this text input.
*
* @param style - The style to use
*/
setStyle(style: TextInputStyle): this;
/**
* Sets the minimum length of text for this text input.
*
* @param minLength - The minimum length of text for this text input
*/
setMinLength(minLength: number): this;
/**
* Sets the maximum length of text for this text input.
*
* @param maxLength - The maximum length of text for this text input
*/
setMaxLength(maxLength: number): this;
/**
* Sets the placeholder for this text input.
*
* @param placeholder - The placeholder to use
*/
setPlaceholder(placeholder: string): this;
/**
* Sets the value for this text input.
*
* @param value - The value to use
*/
setValue(value: string): this;
/**
* Sets whether this text input is required.
*
* @param required - Whether this text input is required
*/
setRequired(required?: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APITextInputComponent;
/**
* Whether this is equal to another structure.
*/
equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean;
}
/**
* The builders that may be used for modals.
*/
type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder;
/**
* The builders that may be used within an action row for messages.
*/
type MessageActionRowComponentBuilder = ButtonBuilder | ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder;
/**
* The builders that may be used within an action row for modals.
*/
type ModalActionRowComponentBuilder = TextInputBuilder;
/**
* Any builder.
*/
type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder;
/**
* A builder that creates API-compatible JSON data for action rows.
*
* @typeParam ComponentType - The types of components this action row holds
*/
declare class ActionRowBuilder<ComponentType extends AnyComponentBuilder> extends ComponentBuilder<APIActionRowComponent<APIComponentInMessageActionRow | APIComponentInModalActionRow>> {
/**
* The components within this action row.
*/
readonly components: ComponentType[];
/**
* 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 }?: Partial<APIActionRowComponent<APIComponentInActionRow>>);
/**
* Adds components to this action row.
*
* @param components - The components to add
*/
addComponents(...components: RestOrArray<ComponentType>): this;
/**
* Sets components for this action row.
*
* @param components - The components to set
*/
setComponents(...components: RestOrArray<ComponentType>): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APIActionRowComponent<ReturnType<ComponentType['toJSON']>>;
}
/**
* A builder that creates API-compatible JSON data for checkboxes.
*/
declare class CheckboxBuilder extends ComponentBuilder<APICheckboxComponent> {
/**
* 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?: Partial<APICheckboxComponent>);
/**
* Sets the custom id of this checkbox.
*
* @param customId - The custom id to use
*/
setCustomId(customId: string): this;
/**
* Sets whether this checkbox is checked by default.
*
* @param isDefault - Whether the checkbox should be checked by default
*/
setDefault(isDefault: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APICheckboxComponent;
}
/**
* A builder that creates API-compatible JSON data for checkbox group options.
*/
declare class CheckboxGroupOptionBuilder implements JSONEncodable<APICheckboxGroupOption> {
data: Partial<APICheckboxGroupOption>;
/**
* 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?: Partial<APICheckboxGroupOption>);
/**
* Sets the label for this option.
*
* @param label - The label to use
*/
setLabel(label: string): this;
/**
* Sets the value for this option.
*
* @param value - The value to use
*/
setValue(value: string): this;
/**
* Sets the description for this option.
*
* @param description - The description to use
*/
setDescription(description: string): this;
/**
* Sets whether this option is selected by default.
*
* @param isDefault - Whether the option should be selected by default
*/
setDefault(isDefault: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APICheckboxGroupOption;
}
/**
* A builder that creates API-compatible JSON data for checkbox groups.
*/
declare class CheckboxGroupBuilder extends ComponentBuilder<APICheckboxGroupComponent> {
/**
* The options within this checkbox group.
*/
readonly options: CheckboxGroupOptionBuilder[];
/**
* 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?: Partial<APICheckboxGroupComponent>);
/**
* Sets the custom id of this checkbox group.
*
* @param customId - The custom id to use
*/
setCustomId(customId: string): this;
/**
* Adds options to this checkbox group.
*
* @param options - The options to add
*/
addOptions(...options: RestOrArray<APICheckboxGroupOption | CheckboxGroupOptionBuilder>): this;
/**
* Sets the options for this checkbox group.
*
* @param options - The options to use
*/
setOptions(...options: RestOrArray<APICheckboxGroupOption | CheckboxGroupOptionBuilder>): this;
/**
* 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: number, deleteCount: number, ...options: RestOrArray<APICheckboxGroupOption | CheckboxGroupOptionBuilder>): this;
/**
* Sets the minimum number of options that must be selected.
*
* @param minValues - The minimum number of options that must be selected
*/
setMinValues(minValues: number): this;
/**
* Sets the maximum number of options that can be selected.
*
* @param maxValues - The maximum number of options that can be selected
*/
setMaxValues(maxValues: number): this;
/**
* Sets whether selecting options is required.
*
* @param required - Whether selecting options is required
*/
setRequired(required: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APICheckboxGroupComponent;
}
/**
* A builder that creates API-compatible JSON data for radio group options.
*/
declare class RadioGroupOptionBuilder implements JSONEncodable<APIRadioGroupOption> {
data: Partial<APIRadioGroupOption>;
/**
* 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?: Partial<APIRadioGroupOption>);
/**
* Sets the label for this option.
*
* @param label - The label to use
*/
setLabel(label: string): this;
/**
* Sets the value for this option.
*
* @param value - The value to use
*/
setValue(value: string): this;
/**
* Sets the description for this option.
*
* @param description - The description to use
*/
setDescription(description: string): this;
/**
* Sets whether this option is selected by default.
*
* @param isDefault - Whether the option should be selected by default
*/
setDefault(isDefault: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APIRadioGroupOption;
}
/**
* A builder that creates API-compatible JSON data for radio groups.
*/
declare class RadioGroupBuilder extends ComponentBuilder<APIRadioGroupComponent> {
/**
* The options within this radio group.
*/
readonly options: RadioGroupOptionBuilder[];
/**
* 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?: Partial<APIRadioGroupComponent>);
/**
* Sets the custom id of this radio group.
*
* @param customId - The custom id to use
*/
setCustomId(customId: string): this;
/**
* Adds options to this radio group.
*
* @param options - The options to add
*/
addOptions(...options: RestOrArray<APIRadioGroupOption | RadioGroupOptionBuilder>): this;
/**
* Sets the options for this radio group.
*
* @param options - The options to use
*/
setOptions(...options: RestOrArray<APIRadioGroupOption | RadioGroupOptionBuilder>): this;
/**
* 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: number, deleteCount: number, ...options: RestOrArray<APIRadioGroupOption | RadioGroupOptionBuilder>): this;
/**
* Sets whether selecting options is required.
*
* @param required - Whether selecting options is required
*/
setRequired(required: boolean): this;
/**
* {@inheritDoc ComponentBuilder.toJSON}
*/
toJSON(): APIRadioGroupComponent;
}
/**
* A builder that creates API-compatible JSON data for file uploads.
*/
declare class FileUploadBuilder extends ComponentBuilder<APIFileUploadComponent> {
/**
* Creates a new file upload.
*
* @param data - The API data to create this file upload with
* @example
* Cr