From e71c76c7f795837dbcc3576e507bd286640b4296 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sun, 6 Mar 2022 15:27:44 +0000 Subject: [PATCH] types(ActionRow): allow components to be passed to constructors (#7531) Co-authored-by: SpaceEEC --- packages/discord.js/src/structures/ActionRow.js | 9 ++++++--- packages/discord.js/typings/index.d.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/discord.js/src/structures/ActionRow.js b/packages/discord.js/src/structures/ActionRow.js index 450a9f325..cc43ffe73 100644 --- a/packages/discord.js/src/structures/ActionRow.js +++ b/packages/discord.js/src/structures/ActionRow.js @@ -1,11 +1,14 @@ 'use strict'; -const { ActionRow: BuildersActionRow } = require('@discordjs/builders'); +const { ActionRow: BuildersActionRow, Component } = require('@discordjs/builders'); const Transformers = require('../util/Transformers'); class ActionRow extends BuildersActionRow { - constructor(data) { - super(Transformers.toSnakeCase(data)); + constructor({ components, ...data } = {}) { + super({ + components: components?.map(c => (c instanceof Component ? c : Transformers.toSnakeCase(c))), + ...Transformers.toSnakeCase(data), + }); } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index fccd5d39b..82a92a5a4 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -209,10 +209,14 @@ export interface BaseComponentData { } export type MessageActionRowComponentData = ButtonComponentData | SelectMenuComponentData; + export type ModalActionRowComponentData = TextInputComponentData; -export interface ActionRowData - extends BaseComponentData { +export type ActionRowComponentData = MessageActionRowComponentData | ModalActionRowComponentData; + +export type ActionRowComponent = MessageActionRowComponent | ModalActionRowComponent; + +export interface ActionRowData extends BaseComponentData { components: T[]; }