diff --git a/packages/discord.js/src/structures/ActionRow.js b/packages/discord.js/src/structures/ActionRow.js index 3d3b247db..b2a09d38d 100644 --- a/packages/discord.js/src/structures/ActionRow.js +++ b/packages/discord.js/src/structures/ActionRow.js @@ -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; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 494474b0c..115583679 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -246,9 +246,12 @@ export class ActionRowBuilder< export type MessageActionRowComponent = ButtonComponent | SelectMenuComponent; export type ModalActionRowComponent = TextInputComponent; -export class ActionRow { - private constructor(data: APIActionRowComponent); +export class ActionRow extends Component< + APIActionRowComponent +> { + private constructor(data: APIActionRowComponent); public readonly components: T[]; + public toJSON(): APIActionRowComponent>; } export class ActivityFlagsBitField extends BitField { @@ -527,7 +530,12 @@ export class ButtonInteraction extends Mes public inRawGuild(): this is ButtonInteraction<'raw'>; } -export class Component { +export type AnyComponent = + | APIMessageComponent + | APIModalComponent + | APIActionRowComponent; + +export class Component { public readonly data: Readonly; public get type(): T['type']; public toJSON(): T;