feat: components v2 in builders v1 (#10787)

* feat(builders): components v2 in builders v1

* feat: implemented the first components

* fix: tests

* fix: tests

* fix: export the new stuff

* feat: add rest of components

* feat: add callback syntax

* feat: callback syntax for section

* fix: missing implements

* fix: accessory property

* fix: apply suggestions from v2 PR

* chore: bring in line with builders v2

* fix: add missing type

* chore: split accessory methods

* chore: backport changes from v2 PR

* fix: accent_color is nullish

* fix: allow passing raw json to MediaGallery methods

* fix: add test

* chore: add Container#addXComponents

* fix: docs

* chore: bump discord-api-types

* Update packages/builders/src/components/Assertions.ts

Co-authored-by: Denis-Adrian Cristea <didinele.dev@gmail.com>

---------

Co-authored-by: Denis-Adrian Cristea <didinele.dev@gmail.com>
This commit is contained in:
Qjuh
2025-04-24 21:59:58 +02:00
committed by GitHub
parent 53dbc96194
commit 118e682682
31 changed files with 1955 additions and 120 deletions

View File

@@ -111,13 +111,13 @@ import {
AuditLogEvent,
APIMessageComponentEmoji,
EmbedType,
APIActionRowComponentTypes,
APIComponentInActionRow,
APIModalInteractionResponseCallbackData,
APIModalSubmitInteraction,
APIMessageActionRowComponent,
APIComponentInMessageActionRow,
TextInputStyle,
APITextInputComponent,
APIModalActionRowComponent,
APIComponentInModalActionRow,
APIModalComponent,
APISelectMenuOption,
APIEmbedField,
@@ -285,7 +285,7 @@ export interface BaseComponentData {
}
export type MessageActionRowComponentData =
| JSONEncodable<APIMessageActionRowComponent>
| JSONEncodable<APIComponentInMessageActionRow>
| ButtonComponentData
| StringSelectMenuComponentData
| UserSelectMenuComponentData
@@ -293,13 +293,13 @@ export type MessageActionRowComponentData =
| MentionableSelectMenuComponentData
| ChannelSelectMenuComponentData;
export type ModalActionRowComponentData = JSONEncodable<APIModalActionRowComponent> | TextInputComponentData;
export type ModalActionRowComponentData = JSONEncodable<APIComponentInModalActionRow> | TextInputComponentData;
export type ActionRowComponentData = MessageActionRowComponentData | ModalActionRowComponentData;
export type ActionRowComponent = MessageActionRowComponent | ModalActionRowComponent;
export interface ActionRowData<ComponentType extends JSONEncodable<APIActionRowComponentTypes> | ActionRowComponentData>
export interface ActionRowData<ComponentType extends JSONEncodable<APIComponentInActionRow> | ActionRowComponentData>
extends BaseComponentData {
components: readonly ComponentType[];
}
@@ -309,8 +309,8 @@ export class ActionRowBuilder<
> extends BuilderActionRow<ComponentType> {
public constructor(
data?: Partial<
| ActionRowData<ActionRowComponentData | JSONEncodable<APIActionRowComponentTypes>>
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
| ActionRowData<ActionRowComponentData | JSONEncodable<APIComponentInActionRow>>
| APIActionRowComponent<APIComponentInMessageActionRow | APIComponentInModalActionRow>
>,
);
public static from<ComponentType extends AnyComponentBuilder = AnyComponentBuilder>(
@@ -330,9 +330,9 @@ export type MessageActionRowComponent =
export type ModalActionRowComponent = TextInputComponent;
export class ActionRow<ComponentType extends MessageActionRowComponent | ModalActionRowComponent> extends Component<
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
APIActionRowComponent<APIComponentInMessageActionRow | APIComponentInModalActionRow>
> {
private constructor(data: APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>);
private constructor(data: APIActionRowComponent<APIComponentInMessageActionRow | APIComponentInModalActionRow>);
public readonly components: ComponentType[];
public toJSON(): APIActionRowComponent<ReturnType<ComponentType['toJSON']>>;
}
@@ -740,7 +740,7 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
export type AnyComponent =
| APIMessageComponent
| APIModalComponent
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>;
| APIActionRowComponent<APIComponentInMessageActionRow | APIComponentInModalActionRow>;
export class Component<RawComponentData extends AnyComponent = AnyComponent> {
public readonly data: Readonly<RawComponentData>;
@@ -2086,7 +2086,13 @@ export interface MessageCall {
participants: readonly Snowflake[];
}
export type MessageComponentType = Exclude<ComponentType, ComponentType.TextInput | ComponentType.ActionRow>;
export type MessageComponentType =
| ComponentType.Button
| ComponentType.ChannelSelect
| ComponentType.MentionableSelect
| ComponentType.RoleSelect
| ComponentType.StringSelect
| ComponentType.UserSelect;
export interface MessageCollectorOptionsParams<
ComponentType extends MessageComponentType,
@@ -2278,9 +2284,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public get component(): CacheTypeReducer<
Cached,
MessageActionRowComponent,
Exclude<APIMessageComponent, APIActionRowComponent<APIMessageActionRowComponent>>,
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageActionRowComponent>>,
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageActionRowComponent>>
Exclude<APIMessageComponent, APIActionRowComponent<APIComponentInMessageActionRow>>,
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIComponentInMessageActionRow>>,
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIComponentInMessageActionRow>>
>;
public componentType: Exclude<ComponentType, ComponentType.ActionRow | ComponentType.TextInput>;
public customId: string;
@@ -2457,7 +2463,7 @@ export interface ModalComponentData {
customId: string;
title: string;
components: readonly (
| JSONEncodable<APIActionRowComponent<APIModalActionRowComponent>>
| JSONEncodable<APIActionRowComponent<APIComponentInModalActionRow>>
| ActionRowData<ModalActionRowComponentData>
)[];
}
@@ -6454,9 +6460,9 @@ export interface BaseMessageOptions {
| AttachmentPayload
)[];
components?: readonly (
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>>
| JSONEncodable<APIActionRowComponent<APIComponentInMessageActionRow>>
| ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>
| APIActionRowComponent<APIMessageActionRowComponent>
| APIActionRowComponent<APIComponentInMessageActionRow>
)[];
poll?: PollData;
}

View File

@@ -25,7 +25,7 @@ import {
ApplicationCommandType,
APIMessage,
APIActionRowComponent,
APIActionRowComponentTypes,
APIComponentInActionRow,
APIStringSelectComponent,
APIUserSelectComponent,
APIRoleSelectComponent,
@@ -2347,7 +2347,7 @@ EmbedBuilder.from(embedData);
declare const embedComp: Embed;
EmbedBuilder.from(embedComp);
declare const actionRowData: APIActionRowComponent<APIActionRowComponentTypes>;
declare const actionRowData: APIActionRowComponent<APIComponentInActionRow>;
ActionRowBuilder.from(actionRowData);
declare const actionRowComp: ActionRow<ActionRowComponent>;
@@ -2359,7 +2359,7 @@ declare const buttonsActionRowComp: ActionRow<ButtonComponent>;
expectType<ActionRowBuilder<ButtonBuilder>>(ActionRowBuilder.from<ButtonBuilder>(buttonsActionRowData));
expectType<ActionRowBuilder<ButtonBuilder>>(ActionRowBuilder.from<ButtonBuilder>(buttonsActionRowComp));
declare const anyComponentsActionRowData: APIActionRowComponent<APIActionRowComponentTypes>;
declare const anyComponentsActionRowData: APIActionRowComponent<APIComponentInActionRow>;
declare const anyComponentsActionRowComp: ActionRow<ActionRowComponent>;
expectType<ActionRowBuilder>(ActionRowBuilder.from(anyComponentsActionRowData));