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
Properties
Commands.bot :: DiscordLuau.BotCommands.logger :: logger.LoggerCommands.registry :: registry.RegistryCommands.loader :: loader.LoaderCommands.context :: anyCommands.middleware :: { Middleware }Commands.afterHooks :: { (classes.TypesCommand) -> () }Commands.cooldowns :: { [string]: number }Commands.concurrency :: { [string]: number }Commands.componentCollectors :: { ComponentCollector }Commands.modalCollectors :: { ModalCollector }Commands.plugins :: { [string]: () -> () }Commands.watchEnabled :: booleanCommands.watchers :: { () -> () }Commands.onError :: ErrorHandlerCommands.onGuardFailed :: GuardFailedHandlerCommands.onConcurrencyLimited :: ConcurrencyLimitedHandlerMethods
Commands:load(directoryPath: string)Commands:watch(directoryPath: string) → () -> ()Commands:getContext() → anyCommands:usePlugin(plugin: PluginDefinition)Commands:unloadPlugin(name: string)Commands:add(commandDefinition: command.CommandDefinition)Commands:remove(name: string)Commands:destroy()Commands:use(middleware: Middleware)Commands:after(hook: (interaction: classes.TypesCommand) -> ())Commands:waitForComponent(options: { filter: ((interaction: classes.Component) -> boolean)?, timeout: number?, }) → future.FutureLike<classes.Component, string>Commands:waitForModal(options: { filter: ((interaction: classes.Modal) -> boolean)?, timeout: number?, }) → future.FutureLike<classes.Modal, string>Commands:dispatchCommand(interaction: classes.TypesCommand)Commands:dispatchComponent(interaction: classes.Component)Commands:dispatchModal(interaction: classes.Modal)Commands:dispatchAutocomplete(interaction: classes.Autocomplete)Commands:registerAsync() → future.FutureLike<string, nil>Commands:registerGuildAsync(guildId: string) → future.FutureLike<string, nil>Commands:unregisterAsync() → future.FutureLike<string, nil>Commands:unregisterGuildAsync(guildId: string) → future.FutureLike<string, nil>Properties
Section titled “Properties”logger
Section titled “logger”registry
Section titled “registry”loader
Section titled “loader”context
Section titled “context”middleware
Section titled “middleware”afterHooks
Section titled “afterHooks”cooldowns
Section titled “cooldowns”{ [string]: number } }
concurrency
Section titled “concurrency”{ [string]: number } }
componentCollectors
Section titled “componentCollectors”modalCollectors
Section titled “modalCollectors”plugins
Section titled “plugins”{ [string]: () -> () } }
watchEnabled
Section titled “watchEnabled”watchers
Section titled “watchers”onError
Section titled “onError”onGuardFailed
Section titled “onGuardFailed”onConcurrencyLimited
Section titled “onConcurrencyLimited”Methods
Section titled “Methods”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
| () -> () |
getContext
Section titled “getContext”Commands : getContext ( ) -> any
Returns the shared context object passed at construction.
Returns
| any |
usePlugin
Section titled “usePlugin”Commands : usePlugin ( plugin ) -> ()
Installs a plugin by calling its setup function. Skips silently if the plugin is already loaded.
Parameters
| plugin: PluginDefinition |
unloadPlugin
Section titled “unloadPlugin”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 |
remove
Section titled “remove”Commands : remove ( name ) -> ()
Unregisters a command by name.
Parameters
| name: string |
destroy
Section titled “destroy”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) -> () |
waitForComponent
Section titled “waitForComponent”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?, } |
Returns
| FutureLike<Component, string> |
waitForModal
Section titled “waitForModal”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?, } |
Returns
| FutureLike<Modal, string> |
dispatchCommand
Section titled “dispatchCommand”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 |
dispatchComponent
Section titled “dispatchComponent”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 |
dispatchModal
Section titled “dispatchModal”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 |
dispatchAutocomplete
Section titled “dispatchAutocomplete”Commands : dispatchAutocomplete ( interaction ) -> ()
Routes an autocomplete interaction to the handler registered for the focused command or subcommand.
Parameters
| interaction: Autocomplete |
registerAsync
Section titled “registerAsync”Commands : registerAsync ( ) -> FutureLike<string, nil>
Uploads all registered commands globally to Discord, overwriting any previously registered commands.
Returns
| FutureLike<string, nil> |
registerGuildAsync
Section titled “registerGuildAsync”Commands : registerGuildAsync ( guildId ) -> FutureLike<string, nil>
Uploads all registered commands to a specific guild, overwriting that guild's commands.
Parameters
| guildId: string |
Returns
| FutureLike<string, nil> |
unregisterAsync
Section titled “unregisterAsync”Commands : unregisterAsync ( ) -> FutureLike<string, nil>
Clears all globally registered commands on Discord.
Returns
| FutureLike<string, nil> |
unregisterGuildAsync
Section titled “unregisterGuildAsync”Commands : unregisterGuildAsync ( guildId ) -> FutureLike<string, nil>
Clears all commands registered to a specific guild on Discord.
Parameters
| guildId: string |
Returns
| FutureLike<string, nil> |
Functions
Section titled “Functions”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 |