fix(ActionRow): toJSON should include components (#7739)

* fix(ActionRow): toJSON should include components

* Update packages/discord.js/src/structures/ActionRow.js

Co-authored-by: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com>

* types: extend component

Co-authored-by: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com>
Co-authored-by: suneettipirneni <suneettipirneni@icloud.com>
This commit is contained in:
muchnameless
2022-04-12 17:14:57 +02:00
committed by GitHub
parent 8eaec114a9
commit ebb4dfa262
2 changed files with 19 additions and 3 deletions

View File

@@ -17,6 +17,14 @@ class ActionRow extends Component {
*/
this.components = components.map(c => Components.createComponent(c));
}
/**
* Returns the API-compatible JSON for this component
* @returns {APIActionRowComponent}
*/
toJSON() {
return { ...this.data, components: this.components.map(c => c.toJSON()) };
}
}
module.exports = ActionRow;

View File

@@ -246,9 +246,12 @@ export class ActionRowBuilder<
export type MessageActionRowComponent = ButtonComponent | SelectMenuComponent;
export type ModalActionRowComponent = TextInputComponent;
export class ActionRow<T extends MessageActionRowComponent | ModalActionRowComponent> {
private constructor(data: APIActionRowComponent<APIMessageActionRowComponent>);
export class ActionRow<T extends MessageActionRowComponent | ModalActionRowComponent> extends Component<
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
> {
private constructor(data: APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>);
public readonly components: T[];
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>>;
}
export class ActivityFlagsBitField extends BitField<ActivityFlagsString> {
@@ -527,7 +530,12 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
public inRawGuild(): this is ButtonInteraction<'raw'>;
}
export class Component<T extends APIMessageComponent | APIModalComponent = APIMessageComponent | APIModalComponent> {
export type AnyComponent =
| APIMessageComponent
| APIModalComponent
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>;
export class Component<T extends AnyComponent = AnyComponent> {
public readonly data: Readonly<T>;
public get type(): T['type'];
public toJSON(): T;