# Gralonium v0.5.0 — Modular Discord.js Bot Framework & Components V2 Suite > `gralonium` (`npm install gralonium`, MIT, Node.js >=18, peerDependency `discord.js ^14.0.0`) is a lightweight, structured Discord bot framework featuring a unified Slash + Prefix command pipeline (`CommandBuilder`, `GroupBuilder`, `ParamsBuilder`, `Context`), file-based `Loader`, permission/cooldown `Plugins`, global `frameworkError` handling, and a complete Discord Components V2 toolkit (`ComponentsV2Builder`, `V2Text`, `V2View`, `V2Paginator`, `V2PersistentRouter`, `OverflowMenuBuilder`, `V2Adaptive`, `lintComponents`). ## Installation ```bash npm install gralonium discord.js ``` Required client options in `new Gralonium(options)`: `intents` (from `discord.js` `GatewayIntentBits`) and `prefix` (string, array, or async function `(ctx) => string | string[]`). ## Main Exports (`gralonium`) - **Discord.js re-exports:** All exports from `discord.js` (`GatewayIntentBits`, `Partials`, `PermissionFlagsBits`, `MessageFlags`, `ChannelType`, etc.). - **Core:** `Gralonium`, `Loader`, `Context`, `HelpCommand`, `Cooldowns`, `Bucket`, `Errors`, `Plugins`, `GraloniumUtils`. - **Builders:** `CommandBuilder`, `GroupBuilder`, `ParamsBuilder`, `EventBuilder`, `InteractionBuilder`, `Interactions`. - **Components V2:** `ComponentsV2Builder`, `V2Text`, `SelectMenuProxy`, `OverflowMenuBuilder`, `OverflowMenuGroupBuilder`, `MenuActionItemBuilder`, `OverflowMenuProxy`, `MenuActionItemStyle`, `OVERFLOW_MENU_TYPE` (`25`), `MENU_ACTION_ITEM_TYPE` (`26`), `OVERFLOW_FALLBACK_SELECT_PREFIX` (`"__ovf_sel:"`), `mapMenuActionItemStyle`, `lintComponents`. - **Interactive Views & Routers:** `V2View`, `V2Paginator`, `V2Adaptive`, `OverflowMenuInteraction`, `unwrapOverflowFallbackInteraction`, `ensureOverflowInteractionBridge`, `V2PersistentRouter`. - **Subpath export `gralonium/experiments`:** `Paginator`, `Confirmator`, `V2View`, `V2Paginator`, `V2Adaptive`, `V2PersistentRouter`. ## Client Initialization & Loader ```js const path = require("node:path"); const { Gralonium, GatewayIntentBits, Partials } = require("gralonium"); const client = new Gralonium({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], partials: [Partials.Channel], prefix: ".", autoSync: true, replyOnPrefix: true, bindProcessHandlers: true, retryOnRateLimit: true, debug: false, v2Adaptive: { forceMode: null, ttlMs: 15 * 60 * 1000 }, }); client.on("frameworkError", (err, ctx) => { console.error("[FrameworkError]", ctx?.command?.data?.name, err); }); (async () => { await client.load(path.join(__dirname, "commands")); await client.load(path.join(__dirname, "events")); await client.login(process.env.TOKEN); })(); ``` `client.load(dir)` recursively loads `.js` files exporting `{ data, params?, plugins?, code? }` (or `V2PersistentRouter` instances directly). Each module may export a single object or use `data: [ ... ]` where supported by the loader. ## Unified Commands (`CommandBuilder`, `GroupBuilder`, `ParamsBuilder`, `Context`) - **`CommandBuilder`:** Options `{ name, description, aliases, as_prefix, as_slash, guildOnly, multiple_args, defaultMemberPermissions, userPermissions, botPermissions, guards, cooldown: { seconds, bucket }, integrationTypes, contexts, nameLocalizations, descriptionLocalizations }`. Fluent setters: `setName`, `setDescription`, `setAliases`, `allowPrefix`, `allowSlash`, `allowMultipleArgs`, `setGuards`, `setUserPermissions`, `setBotPermissions`, `setCooldown`, `setIntegrationTypes`, `setContexts`, `setNameLocalizations`, `setDescriptionLocalizations`. - **`GroupBuilder`:** Groups subcommands with `.addCommand({ data, params, plugins, code })`. Inherits `as_slash`, `as_prefix`, `guildOnly`, `defaultMemberPermissions`, `userPermissions`, `botPermissions`, `guards`, `integrationTypes`, `contexts`. - **`ParamsBuilder`:** `setQuoted(bool)`, `addString(param)`, `addNumber(param)`, `addInteger(param)`, `addBoolean(param)`, `addMember(param)`, `addUser(param)`, `addChannel(param)`, `addRole(param)`, `addAttachment(param)`. String/Number/Integer params support `choices`, `autocomplete`, `minLength`/`maxLength` or `minValue`/`maxValue`, and `ellipsis: true` (captures all remaining prefix words). - **`Context` (`ctx`):** - Properties: `ctx.bot`, `ctx.message`, `ctx.interaction`, `ctx.author`, `ctx.user`, `ctx.member`, `ctx.guild`, `ctx.channel`, `ctx.isPrefix`, `ctx.isSlash`, `ctx.isInteraction`, `ctx.locale`, `ctx.guildLocale`, `ctx.prefix`, `ctx.args`. - Methods: `ctx.get(paramName)`, `ctx.defer(options?)`, `ctx.send(payload, options?)`, `ctx.reply(payload, options?)`, `ctx.ephemeral(payload, options?)`, `ctx.react(...emojis)`. - `ContextPayload` directly accepts a `string`, a `ComponentsV2Builder` instance, a `V2BuiltPayload`, or a `discord.js` payload object. ## Events & Interactions (`EventBuilder`, `InteractionBuilder`, `Plugins`, `Cooldowns`) - **`EventBuilder`:** `{ name: "ready" | "messageCreate" | ..., once: false, description? }` with `async code(bot, ...args)`. - **`InteractionBuilder`:** `type` from `Interactions`: `Button`, `Modal`, `StringSelectMenu`, `UserSelectMenu`, `RoleSelectMenu`, `ChannelSelectMenu`, `MentionableSelectMenu`, `OverflowMenu`, `Autocomplete`, `UserContextMenu`, `MessageContextMenu`, `ChatInput`, `AnyInteraction`. - Use `prefix: "ticket:"` or `match: /^myid:/` (or predicate `(key, interaction) => boolean`) for dynamic customId matching. - Context menus use `type: Interactions.UserContextMenu` or `Interactions.MessageContextMenu` (`toCommandJSON()` builds type `2` / `3` application commands). - **`Plugins` helpers:** `isGuild`, `isInChannelType(...types)`, `isNSFW`, `isOwner`, `hasBotPerms(...perms)`, `hasAnyBotPerms(...perms)`, `hasPerms(...perms)`, `hasAnyPerms(...perms)`, `cooldown(seconds, bucket)`, `check(predicate)`. - **`Bucket` enum:** `Bucket.Member`, `Bucket.User`, `Bucket.Guild`, `Bucket.Channel`. ## Components V2 Suite (`v0.5.0`) - **`ComponentsV2Builder`:** Creates a root `ContainerBuilder` (`color` / `accentColor`, `spoiler`, `safeMentions`) by default. - Sections & Text: `addText(...)`, `addFields(rows, opts)`, `addSectionBlock(heading, rows, opts)`, `addQuote(text, opts)`, `addSmartText(text, opts)`, `addSection(texts, { thumbnail | button | overflow, fallbackToText })`, `addOverflowSection(texts, opts)`. (Discord rule: a `Section` accepts at most 1 accessory.) - Media & Separators: `addGallery(...)`, `addAttachment(...)`, `addFile(...)`, `addSeparator("small" | "large", divider?)`, `addSpacer("small" | "large")`. - Controls: `addButton(...)`, `addButtonsRow(buttons, { autoWrap })`, `addSelectMenu(...)`, `addUserSelectMenu(...)`, `addRoleSelectMenu(...)`, `addChannelSelectMenu(...)`, `addMentionableSelectMenu(...)`. - Outside container: `.outside()` places subsequent components outside the active container; `.inside({ new: true })` opens a new container. - Static Templates: `ComponentsV2Builder.card(...)`, `.imageView(...)`, `.list(...)`, `.confirm(...)`, `.createTicketMenu(...)`, `.createRoleMenu(...)`, `.createPlanSelector(...)`. - Output & Linting: `.toPayload(opts)`, `.send(ctxOrTarget, opts)`, `.edit(message, opts)`, `.lint(opts)` / `lintComponents(target, opts)`. - **`V2Text` helpers:** `V2Text.heading(text, level?, maxLen?)`, `V2Text.subtext(text, maxLen?)`, `V2Text.code(val)`, `V2Text.fields(rows, opts)`, `V2Text.sectionBlock(heading, rows, opts)`, `V2Text.quote(text, maxLen?, fallback?)`, `V2Text.clip(text, maxLen?, fallback?)`, `V2Text.join(blocks, sep?)`. - **`OverflowMenuBuilder` (Discord Type `25` / `26`) + `V2Adaptive`:** - Supports grouped `MenuActionItemBuilder` items (`Default: 1`, `Danger: 2`, `Link: 3` with `url`), emojis, and descriptions. - `V2Adaptive.send(target, builderOrPayload, opts)` and `V2Adaptive.executeWithFallback(...)` automatically send native Type `25` or transparently fall back to a `StringSelectMenu` (`__ovf_sel:`) until Type `25` is enabled globally, while bridging interactions back as `OverflowMenuInteraction`. - **`V2View`:** Stateful interactive V2 message wrapper with `state`, `setState`, `id(action, ...extra)`, `actions`, `thirdPartyMode` (`"reject" | "allow" | "ephemeral-view"`), `onEnd` (`"disable" | "static" | "delete" | "none"`), `timeout`, and `view.send(ctx)`. - **`V2Paginator`:** Declarative paginated V2 card built on `V2View` (`items`, `perPage`, `pages`, `renderItem`, `renderPage`, `closeButton`, `outsideControls`). - **`V2PersistentRouter`:** Stateless restart-safe component router for persistent buttons/selects/overflow menus (`router.id(action, ...args)`, `schema` arg typing `snowflake|int|bool|string|rest`, declarative `userPermissions`, `botPermissions`, `hierarchy`, `guildOnly`, `inFlight` lock deduplication, and `ctx.reply` / `ctx.replyEphemeral`). Automatically registered by `client.load()`.