UNPKG

simplify-cord

Version:

SimplifyCord is an unofficial extension of the 'discord.js' library. Our extension aims to simplify the development of Discord bots, promoting cleaner code and easier maintenance.

21 lines (15 loc) 753 B
import { ActionRowBuilder, AnyComponentBuilder } from 'discord.js'; function createRow<T extends AnyComponentBuilder>(components: T[] | T[][]): ActionRowBuilder<T> { if (!components || components.length === 0) { throw new Error('CreateRow: Components array cannot be empty'); } const flatComponents = Array.isArray(components[0]) ? components[0] : components; if (flatComponents.length === 0) { throw new Error('CreateRow: Components array cannot be empty'); } if (flatComponents.length > 5) { throw new Error('CreateRow: ActionRow can only contain up to 5 components'); } return new ActionRowBuilder<T>().addComponents(flatComponents as T[]); } export default createRow;