forgeloop add
Usage
forgeloop add command <name> [--description "..."] [--with-subcommands] [--autocomplete]
forgeloop add context-menu <name> [--type user|message]
forgeloop add event <eventName> [--once] [--on]
forgeloop add modal [--custom-id <id> | --regexp <pattern> [--regexp-flags <flags>] | <customId>]
forgeloop add button [--custom-id <id> | --regexp <pattern> [--regexp-flags <flags>] | <customId>]
forgeloop add select-menu [--custom-id <id> | --regexp <pattern> [--regexp-flags <flags>] | <customId>]
Basic preset projects cannot use add — handlers are inline. Error message:
This ForgeLoop project uses the "basic" shape, so commands and events stay inline in index.ts/js. Switch to "modular" or "advanced" to use handler generators.
Wrong subcommand:
Unsupported add target "…". Try "command", "context-menu", "event", "modal", "button", or "select-menu".
Missing name (non-interactive):
Usage: forgeloop add command <name> [--description <text>] [--with-subcommands] [--autocomplete] [--dir <path>]
Usage: forgeloop add context-menu <name> [--type user|message]
Usage: forgeloop add event <eventName> [--once]
Usage: forgeloop add <modal|button|select-menu> [--custom-id <id> | --regexp <pattern> [--regexp-flags <flags>] | <customId>]
Command generator
- Name: letters, numbers, hyphens, underscores — stored lowercase.
- Description: optional; default stub text in the
SlashCommandBuilderif empty. --with-subcommands: scaffold a nesteddemogroup with an example subcommand.--autocomplete: scaffold anautocomplete(...)export and matching option.- Both flags together: generate a nested subcommand example with autocomplete wiring.
Context menu generator
- Target:
--type useror--type message(interactive mode prompts if omitted). - Output: writes a
ContextMenuCommandBuildermodule alongside slash commands insrc/commands. - Naming: accepts letters, numbers, hyphens, and underscores; the visible command name is preserved as entered.
Event generator
- Name: must be a valid Discord.js event identifier (e.g.
messageCreate). --once/--on: controlclient.oncevsclient.on. Default:onceforclientReady, otherwiseonif neither flag is set.
Interaction generators
- Targets:
modal,button,select-menu. - CLI matching: choose one of: full
customId(positional or--custom-id) or--regexp(optional--regexp-flags, defaultu). Custom IDs stay within Discord’s 100 characters. The interactive wizard offers exact or RegExp. - Hand-written modules (no CLI): export
executeplus exactly one of:customId— full string matchcustomIdRegExp—RegExp; the entirecustomIdmust match (execresult equals the full string; use^ … $)parseCustomId(id)— return non-null/undefinedto route; that value is passed as the second argument toexecutematchCustomId(id)— return true to route (no second argument); do not combine withparseCustomId
- Flex route order: among RegExp / parse / match handlers, higher
interactionRoutePriorityruns first; ties use load order. - Routing:
src/interactions/router.tsloads handlers at startup: exactcustomIdmap, then flex routes (sorted by priority). - Ephemeral state: optional
src/lib/interaction-sessions.ts(in-memory TTL). Single-process only; use Redis for multi-shard production. - Files under
src/interactions:router.ts|jsmodals/,buttons/,selectMenus/—<slug>.ts|jsbuttons/example-regex.*,example-parse.*— samples (safe to delete)
Flags
| Flag | Type | Default | Description |
|---|---|---|---|
--dir | string | cwd | Project root containing ForgeLoop config. |
--description | string | — | Only for add command — slash command description. |
--with-subcommands | boolean | — | Only for add command — scaffold a sample subcommand group and handler logic. |
--autocomplete | boolean | — | Only for add command — scaffold a sample autocomplete export and option. |
--type | user | message | — | Only for add context-menu — choose the Discord application command target. |
--once | boolean | — | Only for add event — register with client.once. |
--on | boolean | — | Only for add event — register with client.on. |
--custom-id | string | — | Only for modal/button/select-menu — full customId (mutually exclusive with --regexp). |
--regexp | string | — | Only for modal/button/select-menu — RegExp pattern; full customId must match (mutually exclusive with --custom-id / positional). |
--regexp-flags | string | — | With --regexp only — RegExp flags (default u). Allowed: g, i, m, s, u, y. |
Files written
- Command:
src/commands/<name>.tsor.js(from manifest paths). - Context menu command:
src/commands/<name>.tsor.js. - Event:
src/events/<eventName>.tsor.js. - Modal:
src/interactions/modals/<slug>.tsor.js. - Button:
src/interactions/buttons/<slug>.tsor.js. - Select menu:
src/interactions/selectMenus/<slug>.tsor.js.