Skip to content

Commands

Main entry point for the discord-luau commands framework. Routes slash commands, context menus, components, modals, and autocomplete interactions to their registered handlers.

Supports middleware, per-command guards (AND and OR logic), cooldowns, concurrency limits, option transforms, subcommands, interaction collectors, hot-reloading, and plugins.

Summary

Commands.bot  :: Bot
Commands.logger  :: Logger
Commands.registry  :: Registry
Commands.loader  :: Loader
Commands.context  :: any
Commands.middleware  :: { Middleware }
Commands.afterHooks  :: TypesCommand) -> () }
Commands.cooldowns  :: {
{ [string]: number } }
Commands.concurrency  :: {
{ [string]: number } }
Commands.componentCollectors  :: { ComponentCollector }
Commands.modalCollectors  :: { ModalCollector }
Commands.plugins  :: {
{ [string]: () -> () } }
Commands.watchEnabled  :: boolean
Commands.watchers  :: { () -> () }
Commands.onError  :: ErrorHandler
Commands.onGuardFailed  :: GuardFailedHandler
Commands.onConcurrencyLimited  :: ConcurrencyLimitedHandler
Commands : load ( directoryPath )  -> ()

Recursively loads all .luau command modules found under directoryPath. If watchEnabled is true, also begins watching the directory for changes.

Parameters

directoryPath: string
Commands : watch ( directoryPath )  -> () -> ()

Begins watching directoryPath for command file changes. Returns a stop function.

Parameters

directoryPath: string

Returns

() -> ()
Commands : getContext ( )  -> any

Returns the shared context object passed at construction.

Returns

any
Commands : usePlugin ( plugin )  -> ()

Installs a plugin by calling its setup function. Skips silently if the plugin is already loaded.

Parameters

plugin: PluginDefinition
Commands : unloadPlugin ( name )  -> ()

Unloads a plugin by name, calling its teardown function if one was returned by setup.

Parameters

name: string
Commands : add ( commandDefinition )  -> ()

Registers a command definition directly, without loading from disk.

Parameters

commandDefinition: CommandDefinition
Commands : remove ( name )  -> ()

Unregisters a command by name.

Parameters

name: string
Commands : destroy ( )  -> ()

Stops all active file watchers started via watch.

Commands : use ( middleware )  -> ()

Appends a middleware function to the dispatch pipeline.

Parameters

middleware: Middleware
Commands : after ( hook )  -> ()

Registers a global hook that fires after every command execution, regardless of success or error.

Parameters

hook: TypesCommand) -> ()
Commands : waitForComponent ( options )  -> FutureLike<Component, string>

Wait for a single component interaction that satisfies filter, then resolve with it. If no matching interaction arrives within timeout seconds (default 30), the Future errors with "timeout".

Only the first matching interaction is captured; it is not forwarded to any static component handler.

Parameters

options: {
filter: ((interaction,
timeout: number?,
}
Commands : waitForModal ( options )  -> FutureLike<Modal, string>

Wait for a single modal submission that satisfies filter, then resolve with it. If no matching submission arrives within timeout seconds (default 30), the Future errors with "timeout".

Only the first matching submission is captured; it is not forwarded to any static modal handler.

Parameters

options: {
filter: ((interaction,
timeout: number?,
}
Commands : dispatchCommand ( interaction )  -> ()

Routes a slash command interaction through middleware, guards, cooldowns, concurrency checks, and transforms before invoking the registered command execute handler.

Parameters

interaction: TypesCommand
Commands : dispatchComponent ( interaction )  -> ()

Routes a component interaction to a pending collector, or to the static handler registered under a matching custom ID pattern.

Parameters

interaction: Component
Commands : dispatchModal ( interaction )  -> ()

Routes a modal submission to a pending collector, or to the static handler registered under a matching custom ID pattern.

Parameters

interaction: Modal
Commands : dispatchAutocomplete ( interaction )  -> ()

Routes an autocomplete interaction to the handler registered for the focused command or subcommand.

Parameters

interaction: Autocomplete
Commands : registerAsync ( )  -> FutureLike<string, nil>

Uploads all registered commands globally to Discord, overwriting any previously registered commands.

Commands : registerGuildAsync ( guildId )  -> FutureLike<string, nil>

Uploads all registered commands to a specific guild, overwriting that guild's commands.

Parameters

guildId: string
Commands : unregisterAsync ( )  -> FutureLike<string, nil>

Clears all globally registered commands on Discord.

Commands : unregisterGuildAsync ( guildId )  -> FutureLike<string, nil>

Clears all commands registered to a specific guild on Discord.

Parameters

guildId: string
Commands . new ( bot options )  -> Commands

Constructs a Commands instance, wires it to the bot's interaction events, and optionally registers the built-in /help command (enabled by default; set options.help = false to disable). File watching on load is enabled by default; set options.watch = false to disable.

Parameters

bot: any
options: {
help: boolean?,
watch: boolean?,
context: any?,
onError: ErrorHandler,
onGuardFailed: GuardFailedHandler,
}

Returns

Commands