Skip to main content

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 SlashCommandBuilder if empty.
  • --with-subcommands: scaffold a nested demo group with an example subcommand.
  • --autocomplete: scaffold an autocomplete(...) export and matching option.
  • Both flags together: generate a nested subcommand example with autocomplete wiring.

Context menu generator

  • Target: --type user or --type message (interactive mode prompts if omitted).
  • Output: writes a ContextMenuCommandBuilder module alongside slash commands in src/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: control client.once vs client.on. Default: once for clientReady, otherwise on if 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, default u). Custom IDs stay within Discord’s 100 characters. The interactive wizard offers exact or RegExp.
  • Hand-written modules (no CLI): export execute plus exactly one of:
    • customId — full string match
    • customIdRegExpRegExp; the entire customId must match (exec result equals the full string; use ^ … $)
    • parseCustomId(id) — return non-null/undefined to route; that value is passed as the second argument to execute
    • matchCustomId(id) — return true to route (no second argument); do not combine with parseCustomId
  • Flex route order: among RegExp / parse / match handlers, higher interactionRoutePriority runs first; ties use load order.
  • Routing: src/interactions/router.ts loads handlers at startup: exact customId map, 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|js
    • modals/, buttons/, selectMenus/<slug>.ts|js
    • buttons/example-regex.*, example-parse.* — samples (safe to delete)

Flags

FlagTypeDefaultDescription
--dirstringcwdProject root containing ForgeLoop config.
--descriptionstringOnly for add command — slash command description.
--with-subcommandsbooleanOnly for add command — scaffold a sample subcommand group and handler logic.
--autocompletebooleanOnly for add command — scaffold a sample autocomplete export and option.
--typeuser | messageOnly for add context-menu — choose the Discord application command target.
--oncebooleanOnly for add event — register with client.once.
--onbooleanOnly for add event — register with client.on.
--custom-idstringOnly for modal/button/select-menu — full customId (mutually exclusive with --regexp).
--regexpstringOnly for modal/button/select-menu — RegExp pattern; full customId must match (mutually exclusive with --custom-id / positional).
--regexp-flagsstringWith --regexp only — RegExp flags (default u). Allowed: g, i, m, s, u, y.

Files written

  • Command: src/commands/<name>.ts or .js (from manifest paths).
  • Context menu command: src/commands/<name>.ts or .js.
  • Event: src/events/<eventName>.ts or .js.
  • Modal: src/interactions/modals/<slug>.ts or .js.
  • Button: src/interactions/buttons/<slug>.ts or .js.
  • Select menu: src/interactions/selectMenus/<slug>.ts or .js.