From ebb4dfa262adb2086c83db487002bb2e1ed5ab88 Mon Sep 17 00:00:00 2001 From: muchnameless <12682826+muchnameless@users.noreply.github.com> Date: Tue, 12 Apr 2022 17:14:57 +0200 Subject: [PATCH] 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 --- packages/discord.js/src/structures/ActionRow.js | 8 ++++++++ packages/discord.js/typings/index.d.ts | 14 +++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) 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;