mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
docs: add missing, fix existing (#10842)
* docs: add missing, fix existing * refactor: new stuff * fix: requested changes * fix: use `@link` for `@mixes` Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> * chore: disable bad eslint rule --------- Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -16,9 +16,17 @@ export interface CommandData
|
||||
>
|
||||
> {}
|
||||
|
||||
/**
|
||||
* The base class for all command builders.
|
||||
*/
|
||||
export abstract class CommandBuilder<Command extends RESTPostAPIApplicationCommandsJSONBody>
|
||||
implements JSONEncodable<Command>
|
||||
{
|
||||
/**
|
||||
* The API data associated with this command.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: CommandData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,9 @@ export interface SharedNameData
|
||||
* This mixin holds name and description symbols for chat input commands.
|
||||
*/
|
||||
export class SharedName {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected readonly data: SharedNameData = {};
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,9 @@ export interface SharedNameAndDescriptionData
|
||||
* This mixin holds name and description symbols for chat input commands.
|
||||
*/
|
||||
export class SharedNameAndDescription extends SharedName {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected override readonly data: SharedNameAndDescriptionData = {};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable jsdoc/valid-types */
|
||||
import { ApplicationCommandType, type RESTPostAPIChatInputApplicationCommandsJSONBody } from 'discord-api-types/v10';
|
||||
import { Mixin } from 'ts-mixer';
|
||||
import { validate } from '../../../util/validation.js';
|
||||
|
||||
@@ -26,8 +26,16 @@ export class ChatInputCommandSubcommandGroupBuilder
|
||||
extends SharedNameAndDescription
|
||||
implements JSONEncodable<APIApplicationCommandSubcommandGroupOption>
|
||||
{
|
||||
/**
|
||||
* The API data associated with this subcommand group.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ChatInputCommandSubcommandGroupData & SharedNameAndDescriptionData;
|
||||
|
||||
/**
|
||||
* The options within this subcommand group.
|
||||
*/
|
||||
public get options(): readonly ChatInputCommandSubcommandBuilder[] {
|
||||
return (this.data.options ??= []);
|
||||
}
|
||||
@@ -78,6 +86,8 @@ export class ChatInputCommandSubcommandGroupBuilder
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for chat input command subcommands.
|
||||
*
|
||||
* @mixes {@link SharedNameAndDescription}
|
||||
* @mixes {@link SharedChatInputCommandOptions}
|
||||
* @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}
|
||||
*/
|
||||
export class ChatInputCommandSubcommandBuilder
|
||||
|
||||
@@ -7,6 +7,9 @@ export interface ApplicationCommandNumericOptionMinMaxValueData
|
||||
* This mixin holds minimum and maximum symbols used for options.
|
||||
*/
|
||||
export abstract class ApplicationCommandNumericOptionMinMaxValueMixin {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandNumericOptionMinMaxValueData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,9 @@ export interface ApplicationCommandOptionChannelTypesData
|
||||
* This mixin holds channel type symbols used for options.
|
||||
*/
|
||||
export class ApplicationCommandOptionChannelTypesMixin {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandOptionChannelTypesData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,9 @@ export interface ApplicationCommandOptionWithAutocompleteData extends Pick<Autoc
|
||||
* This mixin holds choices and autocomplete symbols used for options.
|
||||
*/
|
||||
export class ApplicationCommandOptionWithAutocompleteMixin {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandOptionWithAutocompleteData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,8 +8,13 @@ export interface ApplicationCommandOptionWithChoicesData {
|
||||
|
||||
/**
|
||||
* This mixin holds choices and autocomplete symbols used for options.
|
||||
*
|
||||
* @typeParam ChoiceType - The type of the choices within this option
|
||||
*/
|
||||
export class ApplicationCommandOptionWithChoicesMixin<ChoiceType extends number | string> {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandOptionWithChoicesData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,12 +17,16 @@ export interface SharedChatInputCommandOptionsData {
|
||||
|
||||
/**
|
||||
* This mixin holds symbols that can be shared in chat input command options.
|
||||
*
|
||||
* @typeParam TypeAfterAddingOptions - The type this class should return after adding an option.
|
||||
*/
|
||||
export class SharedChatInputCommandOptions {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: SharedChatInputCommandOptionsData;
|
||||
|
||||
/**
|
||||
* The options within this command.
|
||||
*/
|
||||
public get options(): readonly ApplicationCommandOptionBase[] {
|
||||
return (this.data.options ??= []);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,11 @@ export interface SharedChatInputCommandSubcommandsData {
|
||||
|
||||
/**
|
||||
* This mixin holds symbols that can be shared in chat input subcommands.
|
||||
*
|
||||
* @typeParam TypeAfterAddingSubcommands - The type this class should return after adding a subcommand or subcommand group.
|
||||
*/
|
||||
export class SharedChatInputCommandSubcommands {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: SharedChatInputCommandSubcommandsData;
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,21 @@ export abstract class ApplicationCommandOptionBase
|
||||
extends SharedNameAndDescription
|
||||
implements JSONEncodable<APIApplicationCommandBasicOption>
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static readonly predicate: z.ZodTypeAny = basicOptionPredicate;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandOptionBaseData & SharedNameAndDescriptionData;
|
||||
|
||||
/**
|
||||
* Creates a new application command option builder.
|
||||
*
|
||||
* @param type - The type of the option
|
||||
*/
|
||||
public constructor(type: ApplicationCommandOptionType) {
|
||||
super();
|
||||
this.data.type = type;
|
||||
|
||||
@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
* A chat input command attachment option.
|
||||
*/
|
||||
export class ChatInputCommandAttachmentOption extends ApplicationCommandOptionBase {
|
||||
/**
|
||||
* Creates a new attachment option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Attachment);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
* A chat input command boolean option.
|
||||
*/
|
||||
export class ChatInputCommandBooleanOption extends ApplicationCommandOptionBase {
|
||||
/**
|
||||
* Creates a new boolean option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Boolean);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,22 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
|
||||
/**
|
||||
* A chat input command channel option.
|
||||
*
|
||||
* @mixes {@link ApplicationCommandOptionBase}
|
||||
* @mixes {@link ApplicationCommandOptionChannelTypesMixin}
|
||||
*/
|
||||
export class ChatInputCommandChannelOption extends Mixin(
|
||||
ApplicationCommandOptionBase,
|
||||
ApplicationCommandOptionChannelTypesMixin,
|
||||
) {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static override readonly predicate = channelOptionPredicate;
|
||||
|
||||
/**
|
||||
* Creates a new channel option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Channel);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
|
||||
/**
|
||||
* A chat input command integer option.
|
||||
*
|
||||
* @mixes {@link ApplicationCommandOptionBase}
|
||||
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
|
||||
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
|
||||
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
|
||||
*/
|
||||
export class ChatInputCommandIntegerOption extends Mixin(
|
||||
ApplicationCommandOptionBase,
|
||||
@@ -15,8 +20,14 @@ export class ChatInputCommandIntegerOption extends Mixin(
|
||||
ApplicationCommandOptionWithAutocompleteMixin,
|
||||
ApplicationCommandOptionWithChoicesMixin<number>,
|
||||
) {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static override readonly predicate = integerOptionPredicate;
|
||||
|
||||
/**
|
||||
* Creates a new integer option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Integer);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
* A chat input command mentionable option.
|
||||
*/
|
||||
export class ChatInputCommandMentionableOption extends ApplicationCommandOptionBase {
|
||||
/**
|
||||
* Creates a new mentionable option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Mentionable);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
|
||||
/**
|
||||
* A chat input command number option.
|
||||
*
|
||||
* @mixes {@link ApplicationCommandOptionBase}
|
||||
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
|
||||
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
|
||||
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
|
||||
*/
|
||||
export class ChatInputCommandNumberOption extends Mixin(
|
||||
ApplicationCommandOptionBase,
|
||||
@@ -15,8 +20,14 @@ export class ChatInputCommandNumberOption extends Mixin(
|
||||
ApplicationCommandOptionWithAutocompleteMixin,
|
||||
ApplicationCommandOptionWithChoicesMixin<number>,
|
||||
) {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static override readonly predicate = numberOptionPredicate;
|
||||
|
||||
/**
|
||||
* Creates a new number option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Number);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
* A chat input command role option.
|
||||
*/
|
||||
export class ChatInputCommandRoleOption extends ApplicationCommandOptionBase {
|
||||
/**
|
||||
* Creates a new role option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.Role);
|
||||
}
|
||||
|
||||
@@ -10,19 +10,32 @@ import type { ApplicationCommandOptionBaseData } from './ApplicationCommandOptio
|
||||
|
||||
/**
|
||||
* A chat input command string option.
|
||||
*
|
||||
* @mixes {@link ApplicationCommandOptionBase}
|
||||
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
|
||||
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<string\>
|
||||
*/
|
||||
export class ChatInputCommandStringOption extends Mixin(
|
||||
ApplicationCommandOptionBase,
|
||||
ApplicationCommandOptionWithAutocompleteMixin,
|
||||
ApplicationCommandOptionWithChoicesMixin<string>,
|
||||
) {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static override readonly predicate = stringOptionPredicate;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare protected readonly data: ApplicationCommandOptionBaseData &
|
||||
ApplicationCommandOptionWithAutocompleteData &
|
||||
ApplicationCommandOptionWithChoicesData &
|
||||
Partial<Pick<APIApplicationCommandStringOption, 'max_length' | 'min_length'>>;
|
||||
|
||||
/**
|
||||
* Creates a new string option builder.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.String);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
|
||||
* A chat input command user option.
|
||||
*/
|
||||
export class ChatInputCommandUserOption extends ApplicationCommandOptionBase {
|
||||
/**
|
||||
* Creates a new user option.
|
||||
*/
|
||||
public constructor() {
|
||||
super(ApplicationCommandOptionType.User);
|
||||
}
|
||||
|
||||
@@ -10,13 +10,26 @@ export type ContextMenuCommandType = ApplicationCommandType.Message | Applicatio
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for context menu commands.
|
||||
*
|
||||
* @mixes {@link CommandBuilder}\<{@link discord-api-types/v10#(RESTPostAPIContextMenuApplicationCommandsJSONBody:interface)}\>
|
||||
* @mixes {@link SharedName}
|
||||
*/
|
||||
export abstract class ContextMenuCommandBuilder extends Mixin(
|
||||
CommandBuilder<RESTPostAPIContextMenuApplicationCommandsJSONBody>,
|
||||
SharedName,
|
||||
) {
|
||||
/**
|
||||
* The API data associated with this context menu command.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
protected override readonly data: Partial<RESTPostAPIContextMenuApplicationCommandsJSONBody>;
|
||||
|
||||
/**
|
||||
* Creates a new context menu command.
|
||||
*
|
||||
* @param data - The API data to create this context menu command with
|
||||
*/
|
||||
public constructor(data: Partial<RESTPostAPIContextMenuApplicationCommandsJSONBody> = {}) {
|
||||
super();
|
||||
this.data = structuredClone(data);
|
||||
|
||||
@@ -3,6 +3,9 @@ import { validate } from '../../../util/validation.js';
|
||||
import { messageCommandPredicate } from './Assertions.js';
|
||||
import { ContextMenuCommandBuilder } from './ContextMenuCommand.js';
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for message context menu commands.
|
||||
*/
|
||||
export class MessageContextCommandBuilder extends ContextMenuCommandBuilder {
|
||||
/**
|
||||
* {@inheritDoc CommandBuilder.toJSON}
|
||||
|
||||
@@ -3,6 +3,9 @@ import { validate } from '../../../util/validation.js';
|
||||
import { userCommandPredicate } from './Assertions.js';
|
||||
import { ContextMenuCommandBuilder } from './ContextMenuCommand.js';
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for user context menu commands.
|
||||
*/
|
||||
export class UserContextCommandBuilder extends ContextMenuCommandBuilder {
|
||||
/**
|
||||
* {@inheritDoc CommandBuilder.toJSON}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
@@ -34,13 +32,15 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new modal from API data.
|
||||
* Creates a new modal.
|
||||
*
|
||||
* @param data - The API data to create this modal with
|
||||
*/
|
||||
public constructor({ components = [], ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {
|
||||
public constructor(data: Partial<APIModalInteractionResponseCallbackData> = {}) {
|
||||
const { components = [], ...rest } = data;
|
||||
|
||||
this.data = {
|
||||
...structuredClone(data),
|
||||
...structuredClone(rest),
|
||||
components: components.map((component) => createComponentBuilder(component)),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user