docs(builders): Add some basic documentation (#9359)

This commit is contained in:
Jiralite
2023-04-10 21:09:51 +01:00
committed by GitHub
parent c0f2dd7131
commit 8073561824
36 changed files with 690 additions and 300 deletions

View File

@@ -15,45 +15,54 @@ import {
validateDMPermission,
} from './Assertions.js';
/**
* The type a context menu command can be.
*/
export type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
/**
* A builder that creates API-compatible JSON data for context menu commands.
*/
export class ContextMenuCommandBuilder {
/**
* The name of this context menu command
* The name of this command.
*/
public readonly name: string = undefined!;
/**
* The localized names for this command
* The name localizations of this command.
*/
public readonly name_localizations?: LocalizationMap;
/**
* The type of this context menu command
* The type of this command.
*/
public readonly type: ContextMenuCommandType = undefined!;
/**
* Whether the command is enabled by default when the app is added to a guild
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated This property is deprecated and will be removed in the future.
* You should use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
public readonly default_permission: boolean | undefined = undefined;
/**
* Set of permissions represented as a bit set for the command
* The set of permissions represented as a bit set for the command.
*/
public readonly default_member_permissions: Permissions | null | undefined = undefined;
/**
* Indicates whether the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* 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.
*/
public readonly dm_permission: boolean | undefined = undefined;
/**
* Sets the name
* Sets the name of this command.
*
* @param name - The name
* @param name - The name to use
*/
public setName(name: string) {
// Assert the name matches the conditions
@@ -65,9 +74,9 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the type
* Sets the type of this command.
*
* @param type - The type
* @param type - The type to use
*/
public setType(type: ContextMenuCommandType) {
// Assert the type is valid
@@ -83,7 +92,7 @@ export class ContextMenuCommandBuilder {
*
* @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
* @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.
*/
@@ -97,7 +106,7 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the default permissions a member should have in order to run the command.
* 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.
@@ -114,10 +123,11 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets if the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* Sets if the command is available in direct messages with the application.
*
* @param enabled - If the command should be enabled in DMs
* @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}
*/
public setDMPermission(enabled: boolean | null | undefined) {
@@ -130,10 +140,10 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets a name localization
* Sets a name localization for this command.
*
* @param locale - The locale to set a description for
* @param localizedName - The localized description for the given locale
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
public setNameLocalization(locale: LocaleString, localizedName: string | null) {
if (!this.name_localizations) {
@@ -154,9 +164,9 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the name localizations
* Sets the name localizations for this command.
*
* @param localizedNames - The dictionary of localized descriptions to set
* @param localizedNames - The object of localized names to set
*/
public setNameLocalizations(localizedNames: LocalizationMap | null) {
if (localizedNames === null) {
@@ -172,7 +182,7 @@ export class ContextMenuCommandBuilder {
}
/**
* Returns the final data that should be sent to Discord.
* Serializes this builder to API-compatible JSON data.
*
* @remarks
* This method runs validations on the data before serializing it.
@@ -186,5 +196,3 @@ export class ContextMenuCommandBuilder {
return { ...this };
}
}
export type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;

View File

@@ -1,3 +1,5 @@
/* eslint-disable jsdoc/check-param-names */
import type { JSONEncodable } from '@discordjs/util';
import type {
APIActionRowComponent,
@@ -10,11 +12,25 @@ import { createComponentBuilder } from '../../components/Components.js';
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
import { titleValidator, validateRequiredParameters } from './Assertions.js';
/**
* A builder that creates API-compatible JSON data for modals.
*/
export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {
/**
* The API data associated with this modal.
*/
public readonly data: Partial<APIModalInteractionResponseCallbackData>;
/**
* The components within this modal.
*/
public readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[] = [];
/**
* Creates a new modal from API data.
*
* @param data - The API data to create this modal with
*/
public constructor({ components, ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {
this.data = { ...data };
this.components = (components?.map((component) => createComponentBuilder(component)) ??
@@ -22,9 +38,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
}
/**
* Sets the title of the modal
* Sets the title of this modal.
*
* @param title - The title of the modal
* @param title - The title to use
*/
public setTitle(title: string) {
this.data.title = titleValidator.parse(title);
@@ -32,9 +48,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
}
/**
* Sets the custom id of the modal
* Sets the custom id of this modal.
*
* @param customId - The custom id of this modal
* @param customId - The custom id to use
*/
public setCustomId(customId: string) {
this.data.custom_id = customIdValidator.parse(customId);
@@ -42,9 +58,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
}
/**
* Adds components to this modal
* Adds components to this modal.
*
* @param components - The components to add to this modal
* @param components - The components to add
*/
public addComponents(
...components: RestOrArray<
@@ -62,9 +78,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
}
/**
* Sets the components in this modal
* Sets components for this modal.
*
* @param components - The components to set this modal to
* @param components - The components to set
*/
public setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>) {
this.components.splice(0, this.components.length, ...normalizeArray(components));

View File

@@ -19,76 +19,61 @@ import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } fro
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';
/**
* A builder that creates API-compatible JSON data for slash commands.
*/
@mix(SharedSlashCommandOptions, SharedNameAndDescription)
export class SlashCommandBuilder {
/**
* The name of this slash command
* The name of this command.
*/
public readonly name: string = undefined!;
/**
* The localized names for this command
* The name localizations of this command.
*/
public readonly name_localizations?: LocalizationMap;
/**
* The description of this slash command
* The description of this command.
*/
public readonly description: string = undefined!;
/**
* The localized descriptions for this command
* The description localizations of this command.
*/
public readonly description_localizations?: LocalizationMap;
/**
* The options of this slash command
* The options of this command.
*/
public readonly options: ToAPIApplicationCommandOptions[] = [];
/**
* Whether the command is enabled by default when the app is added to a guild
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated This property is deprecated and will be removed in the future.
* You should use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead.
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
public readonly default_permission: boolean | undefined = undefined;
/**
* Set of permissions represented as a bit set for the command
* The set of permissions represented as a bit set for the command.
*/
public readonly default_member_permissions: Permissions | null | undefined = undefined;
/**
* Indicates whether the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* 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.
*/
public readonly dm_permission: boolean | undefined = undefined;
/**
* Whether this command is NSFW
* Whether this command is NSFW.
*/
public readonly nsfw: boolean | undefined = undefined;
/**
* Returns the final data that should be sent to Discord.
*
* @remarks
* This method runs validations on the data before serializing it.
* As such, it may throw an error if the data is invalid.
*/
public toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
validateRequiredParameters(this.name, this.description, this.options);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
return {
...this,
options: this.options.map((option) => option.toJSON()),
};
}
/**
* Sets whether the command is enabled by default when the application is added to a guild.
*
@@ -125,10 +110,11 @@ export class SlashCommandBuilder {
}
/**
* Sets if the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* Sets if the command is available in direct messages with the application.
*
* @param enabled - If the command should be enabled in DMs
* @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}
*/
public setDMPermission(enabled: boolean | null | undefined) {
@@ -141,7 +127,7 @@ export class SlashCommandBuilder {
}
/**
* Sets whether this command is NSFW
* Sets whether this command is NSFW.
*
* @param nsfw - Whether this command is NSFW
*/
@@ -153,9 +139,9 @@ export class SlashCommandBuilder {
}
/**
* Adds a new subcommand group to this command
* Adds a new subcommand group to this command.
*
* @param input - A function that returns a subcommand group builder, or an already built builder
* @param input - A function that returns a subcommand group builder or an already built builder
*/
public addSubcommandGroup(
input:
@@ -179,9 +165,9 @@ export class SlashCommandBuilder {
}
/**
* Adds a new subcommand to this command
* Adds a new subcommand to this command.
*
* @param input - A function that returns a subcommand builder, or an already built builder
* @param input - A function that returns a subcommand builder or an already built builder
*/
public addSubcommand(
input:
@@ -203,18 +189,47 @@ export class SlashCommandBuilder {
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.
*/
public toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {
validateRequiredParameters(this.name, this.description, this.options);
validateLocalizationMap(this.name_localizations);
validateLocalizationMap(this.description_localizations);
return {
...this,
options: this.options.map((option) => option.toJSON()),
};
}
}
export interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}
/**
* An interface specifically for slash command subcommands.
*/
export interface SlashCommandSubcommandsOnlyBuilder
extends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> {}
/**
* An interface specifically for slash command options.
*/
export interface SlashCommandOptionsOnlyBuilder
extends SharedNameAndDescription,
SharedSlashCommandOptions,
Pick<SlashCommandBuilder, 'toJSON'> {}
/**
* An interface that ensures the `toJSON()` call will return something
* that can be serialized into API-compatible data.
*/
export interface ToAPIApplicationCommandOptions {
toJSON(): APIApplicationCommandOption;
}

View File

@@ -11,31 +11,31 @@ import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';
/**
* Represents a folder for subcommands
* Represents a folder for subcommands.
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}
*/
@mix(SharedNameAndDescription)
export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions {
/**
* The name of this subcommand group
* The name of this subcommand group.
*/
public readonly name: string = undefined!;
/**
* The description of this subcommand group
* The description of this subcommand group.
*/
public readonly description: string = undefined!;
/**
* The subcommands part of this subcommand group
* The subcommands within this subcommand group.
*/
public readonly options: SlashCommandSubcommandBuilder[] = [];
/**
* Adds a new subcommand to this group
* Adds a new subcommand to this group.
*
* @param input - A function that returns a subcommand builder, or an already built builder
* @param input - A function that returns a subcommand builder or an already built builder
*/
public addSubcommand(
input:
@@ -60,6 +60,13 @@ export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationComma
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.
*/
public toJSON(): APIApplicationCommandSubcommandGroupOption {
validateRequiredParameters(this.name, this.description, this.options);
@@ -77,27 +84,34 @@ export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationComma
export interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription {}
/**
* Represents a subcommand
* A builder that creates API-compatible JSON data for slash command subcommands.
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}
*/
@mix(SharedNameAndDescription, SharedSlashCommandOptions)
export class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions {
/**
* The name of this subcommand
* The name of this subcommand.
*/
public readonly name: string = undefined!;
/**
* The description of this subcommand
* The description of this subcommand.
*/
public readonly description: string = undefined!;
/**
* The options of this subcommand
* The options within this subcommand.
*/
public readonly options: ApplicationCommandOptionBase[] = [];
/**
* 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.
*/
public toJSON(): APIApplicationCommandSubcommandOption {
validateRequiredParameters(this.name, this.description, this.options);

View File

@@ -1,17 +1,26 @@
/**
* This mixin holds minimum and maximum symbols used for options.
*/
export abstract class ApplicationCommandNumericOptionMinMaxValueMixin {
/**
* The maximum value of this option.
*/
public readonly max_value?: number;
/**
* The minimum value of this option.
*/
public readonly min_value?: number;
/**
* Sets the maximum number value of this option
* Sets the maximum number value of this option.
*
* @param max - The maximum value this option can be
*/
public abstract setMaxValue(max: number): this;
/**
* Sets the minimum number value of this option
* Sets the minimum number value of this option.
*
* @param min - The minimum value this option can be
*/

View File

@@ -2,15 +2,26 @@ import type { APIApplicationCommandBasicOption, ApplicationCommandOptionType } f
import { validateRequiredParameters, validateRequired, validateLocalizationMap } from '../Assertions.js';
import { SharedNameAndDescription } from './NameAndDescription.js';
/**
* The base application command option builder that contains common symbols for application command builders.
*/
export abstract class ApplicationCommandOptionBase extends SharedNameAndDescription {
/**
* The type of this option.
*/
public abstract readonly type: ApplicationCommandOptionType;
/**
* Whether this option is required.
*
* @defaultValue `false`
*/
public readonly required: boolean = false;
/**
* Marks the option as required
* Sets whether this option is required.
*
* @param required - If this option should be required
* @param required - Whether this option should be required
*/
public setRequired(required: boolean) {
// Assert that you actually passed a boolean
@@ -21,8 +32,18 @@ export abstract class ApplicationCommandOptionBase extends SharedNameAndDescript
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.
*/
public abstract toJSON(): APIApplicationCommandBasicOption;
/**
* This method runs required validators on this builder.
*/
protected runRequiredValidations() {
validateRequiredParameters(this.name, this.description, []);

View File

@@ -1,7 +1,12 @@
import { s } from '@sapphire/shapeshift';
import { ChannelType } from 'discord-api-types/v10';
// Only allow valid channel types to be used. (This can't be dynamic because const enums are erased at runtime)
/**
* The allowed channel types used for a channel option in a slash command builder.
*
* @privateRemarks This can't be dynamic because const enums are erased at runtime.
* @internal
*/
const allowedChannelTypes = [
ChannelType.GuildText,
ChannelType.GuildVoice,
@@ -14,17 +19,26 @@ const allowedChannelTypes = [
ChannelType.GuildForum,
] as const;
/**
* The type of allowed channel types used for a channel option.
*/
export type ApplicationCommandOptionAllowedChannelTypes = (typeof allowedChannelTypes)[number];
const channelTypesPredicate = s.array(s.union(...allowedChannelTypes.map((type) => s.literal(type))));
/**
* This mixin holds channel type symbols used for options.
*/
export class ApplicationCommandOptionChannelTypesMixin {
/**
* The channel types of this option.
*/
public readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[];
/**
* Adds channel types to this option
* Adds channel types to this option.
*
* @param channelTypes - The channel types to add
* @param channelTypes - The channel types
*/
public addChannelTypes(...channelTypes: ApplicationCommandOptionAllowedChannelTypes[]) {
if (this.channel_types === undefined) {

View File

@@ -11,16 +11,29 @@ const choicesPredicate = s.object({
}).array;
const booleanPredicate = s.boolean;
/**
* This mixin holds choices and autocomplete symbols used for options.
*/
export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> {
/**
* The choices of this option.
*/
public readonly choices?: APIApplicationCommandOptionChoice<T>[];
/**
* Whether this option utilizes autocomplete.
*/
public readonly autocomplete?: boolean;
// Since this is present and this is a mixin, this is needed
/**
* The type of this option.
*
* @privateRemarks Since this is present and this is a mixin, this is needed.
*/
public readonly type!: ApplicationCommandOptionType;
/**
* Adds multiple choices for this option
* Adds multiple choices to this option.
*
* @param choices - The choices to add
*/
@@ -51,6 +64,11 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends n
return this;
}
/**
* Sets multiple choices for this option.
*
* @param choices - The choices to set
*/
public setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this {
if (choices.length > 0 && this.autocomplete) {
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
@@ -65,9 +83,9 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends n
}
/**
* Marks the option as autocompletable
* Whether this option uses autocomplete.
*
* @param autocomplete - If this option should be autocompletable
* @param autocomplete - Whether this option should use autocomplete
*/
public setAutocomplete(autocomplete: boolean): this {
// Assert that you actually passed a boolean

View File

@@ -1,19 +1,34 @@
import type { LocaleString, LocalizationMap } from 'discord-api-types/v10';
import { validateDescription, validateLocale, validateName } from '../Assertions.js';
/**
* This mixin holds name and description symbols for slash commands.
*/
export class SharedNameAndDescription {
/**
* The name of this command.
*/
public readonly name!: string;
/**
* The name localizations of this command.
*/
public readonly name_localizations?: LocalizationMap;
/**
* The description of this command.
*/
public readonly description!: string;
/**
* The description localizations of this command.
*/
public readonly description_localizations?: LocalizationMap;
/**
* Sets the name
* Sets the name of this command.
*
* @param name - The name
* @param name - The name to use
*/
public setName(name: string): this {
// Assert the name matches the conditions
@@ -25,9 +40,9 @@ export class SharedNameAndDescription {
}
/**
* Sets the description
* Sets the description of this command.
*
* @param description - The description
* @param description - The description to use
*/
public setDescription(description: string) {
// Assert the description matches the conditions
@@ -39,10 +54,10 @@ export class SharedNameAndDescription {
}
/**
* Sets a name localization
* SSets a name localization for this command.
*
* @param locale - The locale to set a description for
* @param localizedName - The localized description for the given locale
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
public setNameLocalization(locale: LocaleString, localizedName: string | null) {
if (!this.name_localizations) {
@@ -63,9 +78,9 @@ export class SharedNameAndDescription {
}
/**
* Sets the name localizations
* Sets the name localizations for this command.
*
* @param localizedNames - The dictionary of localized descriptions to set
* @param localizedNames - The object of localized names to set
*/
public setNameLocalizations(localizedNames: LocalizationMap | null) {
if (localizedNames === null) {
@@ -83,9 +98,9 @@ export class SharedNameAndDescription {
}
/**
* Sets a description localization
* Sets a description localization for this command.
*
* @param locale - The locale to set a description for
* @param locale - The locale to set
* @param localizedDescription - The localized description for the given locale
*/
public setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null) {
@@ -107,9 +122,9 @@ export class SharedNameAndDescription {
}
/**
* Sets the description localizations
* Sets the description localizations for this command.
*
* @param localizedDescriptions - The dictionary of localized descriptions to set
* @param localizedDescriptions - The object of localized descriptions to set
*/
public setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null) {
if (localizedDescriptions === null) {

View File

@@ -11,13 +11,18 @@ import { SlashCommandStringOption } from '../options/string.js';
import { SlashCommandUserOption } from '../options/user.js';
import type { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';
/**
* This mixin holds symbols that can be shared in slash command options.
*
* @typeParam ShouldOmitSubcommandFunctions - Whether to omit subcommand functions.
*/
export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
public readonly options!: ToAPIApplicationCommandOptions[];
/**
* Adds a boolean option
* Adds a boolean option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addBooleanOption(
input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption),
@@ -26,18 +31,18 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds a user option
* Adds a user option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)) {
return this._sharedAddOptionMethod(input, SlashCommandUserOption);
}
/**
* Adds a channel option
* Adds a channel option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addChannelOption(
input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption),
@@ -46,18 +51,18 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds a role option
* Adds a role option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)) {
return this._sharedAddOptionMethod(input, SlashCommandRoleOption);
}
/**
* Adds an attachment option
* Adds an attachment option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addAttachmentOption(
input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption),
@@ -66,9 +71,9 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds a mentionable option
* Adds a mentionable option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addMentionableOption(
input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption),
@@ -77,9 +82,9 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds a string option
* Adds a string option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addStringOption(
input:
@@ -97,9 +102,9 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds an integer option
* Adds an integer option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addIntegerOption(
input:
@@ -117,9 +122,9 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
}
/**
* Adds a number option
* Adds a number option.
*
* @param input - A function that returns an option builder, or an already built builder
* @param input - A function that returns an option builder or an already built builder
*/
public addNumberOption(
input:
@@ -136,6 +141,13 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
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
*/
private _sharedAddOptionMethod<T extends ApplicationCommandOptionBase>(
input:
| Omit<T, 'addChoices'>

View File

@@ -1,9 +1,18 @@
import { ApplicationCommandOptionType, type APIApplicationCommandAttachmentOption } from 'discord-api-types/v10';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
/**
* A slash command attachment option.
*/
export class SlashCommandAttachmentOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public override readonly type = ApplicationCommandOptionType.Attachment as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandAttachmentOption {
this.runRequiredValidations();

View File

@@ -1,9 +1,18 @@
import { ApplicationCommandOptionType, type APIApplicationCommandBooleanOption } from 'discord-api-types/v10';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
/**
* A slash command boolean option.
*/
export class SlashCommandBooleanOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.Boolean as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandBooleanOption {
this.runRequiredValidations();

View File

@@ -3,10 +3,19 @@ import { mix } from 'ts-mixer';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
import { ApplicationCommandOptionChannelTypesMixin } from '../mixins/ApplicationCommandOptionChannelTypesMixin.js';
/**
* A slash command channel option.
*/
@mix(ApplicationCommandOptionChannelTypesMixin)
export class SlashCommandChannelOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public override readonly type = ApplicationCommandOptionType.Channel as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandChannelOption {
this.runRequiredValidations();

View File

@@ -7,11 +7,17 @@ import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixi
const numberValidator = s.number.int;
/**
* A slash command integer option.
*/
@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
export class SlashCommandIntegerOption
extends ApplicationCommandOptionBase
implements ApplicationCommandNumericOptionMinMaxValueMixin
{
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.Integer as const;
/**
@@ -36,6 +42,9 @@ export class SlashCommandIntegerOption
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandIntegerOption {
this.runRequiredValidations();

View File

@@ -1,9 +1,18 @@
import { ApplicationCommandOptionType, type APIApplicationCommandMentionableOption } from 'discord-api-types/v10';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
/**
* A slash command mentionable option.
*/
export class SlashCommandMentionableOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.Mentionable as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandMentionableOption {
this.runRequiredValidations();

View File

@@ -7,11 +7,17 @@ import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixi
const numberValidator = s.number;
/**
* A slash command number option.
*/
@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
export class SlashCommandNumberOption
extends ApplicationCommandOptionBase
implements ApplicationCommandNumericOptionMinMaxValueMixin
{
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.Number as const;
/**
@@ -36,6 +42,9 @@ export class SlashCommandNumberOption
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandNumberOption {
this.runRequiredValidations();

View File

@@ -1,9 +1,18 @@
import { ApplicationCommandOptionType, type APIApplicationCommandRoleOption } from 'discord-api-types/v10';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
/**
* A slash command role option.
*/
export class SlashCommandRoleOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public override readonly type = ApplicationCommandOptionType.Role as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandRoleOption {
this.runRequiredValidations();

View File

@@ -7,12 +7,24 @@ import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixi
const minLengthValidator = s.number.greaterThanOrEqual(0).lessThanOrEqual(6_000);
const maxLengthValidator = s.number.greaterThanOrEqual(1).lessThanOrEqual(6_000);
/**
* A slash command string option.
*/
@mix(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
export class SlashCommandStringOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.String as const;
/**
* The maximum length of this option.
*/
public readonly max_length?: number;
/**
* The minimum length of this option.
*/
public readonly min_length?: number;
/**
@@ -41,6 +53,9 @@ export class SlashCommandStringOption extends ApplicationCommandOptionBase {
return this;
}
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandStringOption {
this.runRequiredValidations();

View File

@@ -1,9 +1,18 @@
import { ApplicationCommandOptionType, type APIApplicationCommandUserOption } from 'discord-api-types/v10';
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';
/**
* A slash command user option.
*/
export class SlashCommandUserOption extends ApplicationCommandOptionBase {
/**
* The type of this option.
*/
public readonly type = ApplicationCommandOptionType.User as const;
/**
* {@inheritDoc ApplicationCommandOptionBase.toJSON}
*/
public toJSON(): APIApplicationCommandUserOption {
this.runRequiredValidations();