UNPKG

rashi-discord-bot-lib

Version:

🚀 Powerful Discord bot framework with built-in database, event handling, and utilities

49 lines • 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateRow = CreateRow; const discord_js_1 = require("discord.js"); function CreateRow(components) { return components.map((row, rowIndex) => { // === SELECT MENU === if (!Array.isArray(row)) { const options = row.options.data.map((opt) => { const label = row.options.label ? opt[row.options.label] : opt.label ?? 'Option'; const value = row.options.value ? opt[row.options.value] : opt.value ?? `${Math.random()}`; const description = row.options.description ? opt[row.options.description] : undefined; const emoji = row.options.emoji ? opt[row.options.emoji] : undefined; const builder = new discord_js_1.StringSelectMenuOptionBuilder() .setLabel(label) .setValue(value); if (description) builder.setDescription(description); if (emoji) builder.setEmoji(emoji); return builder; }); const selectMenu = new discord_js_1.StringSelectMenuBuilder() .setCustomId(row.options.id) .setPlaceholder(row.options.placeholder ?? 'Select...') .setMinValues(row.options.min ?? 1) .setMaxValues(row.options.max ?? 1) .addOptions(options); return new discord_js_1.ActionRowBuilder().addComponents(selectMenu); } // === BUTTONS === const buttons = row.map((btn) => { const builder = new discord_js_1.ButtonBuilder() .setCustomId(btn.custom_id) .setStyle(typeof btn.style === 'number' && btn.style >= 1 && btn.style <= 5 ? btn.style : discord_js_1.ButtonStyle.Secondary); if (btn.label) builder.setLabel(btn.label); if (btn.emoji) builder.setEmoji(btn.emoji); if (btn.disabled) builder.setDisabled(true); return builder; }); return new discord_js_1.ActionRowBuilder().addComponents(...buttons); }); } //# sourceMappingURL=discordHelpers.js.map