Client Api
Client/Api is what the console, built-in or your own, talks to. The boot script starts it automatically, and Client.Mount hands it to you:
-- MyConsole.luau, passed as Client.Mount
return function(Api)
local result = Api.run("kick @me being rude")
print(result.ok, result.status, result.message, result.replies)
endEvery lookup is a synchronous table read against the delivered manifest. Only Api.run and a custom type's suggestions() ever touch the network.
Functions
Api.isReady
Api.isReady(): booleanWhether the bundle has connected.
Api.run
Api.run(text: string): ResultDispatches to the server. Yields until the server answers, then returns the result.
If the text resolves to a client command, it runs locally instead. No dispatch is sent and the result is returned without yielding on the network. A record notification is fired for auditing only, and never blocks the call.
Api.parse
Api.parse(text: string): ParseResultParses locally, with no server round trip. Runs the same tokenizer, parser and binder as the server, so a console can underline a bad argument as it is typed.
Api.queryLogs
Api.queryLogs(query: Query?): LogPageAsks the server for a page of log records. Yields until it answers.
local page = Api.queryLogs({ stream = "moderation", search = "bob", days = 7, limit = 40 })| Field | Meaning |
|---|---|
stream | "general" or "moderation"; defaults to "general" |
search | free text matched across names, ids, commands, actions and reasons |
days | how far back to look |
limit | page size |
cursor | the cursor from a previous page, to fetch the next |
Permission is checked server-side on every call. A refusal comes back with ok = false and a status of Denied, Unavailable, RateLimited or Invalid.
Api.getCommands
Api.getCommands(): { Command }The commands in this player's manifest.
Api.getCommand
Api.getCommand(path: { string } | string): Command?One command by path or name, or nil.
Api.getType
Api.getType(name: string): AnyArgType?Resolves an argument type by name.
Api.getSettings
Api.getSettings(): { [string]: any }The client settings the server sent: the Client config table.
Api.setConfirmHandler
Api.setConfirmHandler(handler: ((prompt: string) -> boolean)?): ()Answers destructive confirmations. With no handler installed the answer is no, so destructive commands fail closed.
Api.setConfirmHandler(function(prompt)
return showDialog(prompt)
end)Api.toggle
Api.toggle(visible: boolean?): booleanOpens, closes or flips the console. Omit the argument to flip, pass true to open, false to close. Returns whether it is visible afterwards.
This is the seam for driving the console from outside it: a topbar icon, a settings menu, a keybind of your own.
myIcon.Activated:Connect(function()
Api.toggle()
end)It works against the built-in console with no setup, and against a Client.Mount interface that registered a handler. Returns false and does nothing when no interface is mounted, so it is always safe to call.
Api.setToggleHandler
Api.setToggleHandler(handler: ((visible: boolean?) -> boolean)?): ()Registers what Api.toggle drives. The built-in console installs one when it mounts; a custom interface should install its own so external code can open it. A handler that raises is treated as a refusal, so toggle returns false rather than propagating.
Api.onManifest
Api.onManifest(callback: (manifest: any) -> ()): () -> ()Called whenever the manifest arrives or changes, so a permission change re-renders. Returns a disconnect function.
Replays to a late subscriber. It hands over the manifest already in hand, so a mount function can register a render callback and have it fire immediately rather than waiting for the next permission change.
Api.onShutdown
Api.onShutdown(callback: () -> ()): () -> ()Called once when access is revoked, before the bundle goes. Returns a disconnect function.
Also replays: it fires immediately if the bundle has already been revoked, so a consumer that subscribes after the fact still tears down instead of lingering with a dead remote behind it.
Handlers are each isolated. One that throws is logged and does not stop the others, or the unmount, from completing.
Api.start
Api.start(channel: RemoteEvent, options: StartOptions?): ()Connects the API to its remote. The delivered boot script calls this; a consumer never needs to.
Api.stop
Api.stop(): ()Properties
Api.suggestions
A SuggestionCache for autocomplete.
Types
Result
type Result = {
ok: boolean,
status: string,
message: string?,
replies: { string },
}status is one of the Dispatcher.Status values, plus RateLimited when the token bucket is exhausted.
LogPage
type LogPage = {
ok: boolean,
status: string,
records: { any },
cursor: any?,
truncated: boolean,
}cursor is non-nil when more records match than fit in this page; pass it back to queryLogs for the next one. Record shapes are in LogRecord.
ParseResult
type ParseResult = {
command: any?,
path: { string },
words: { any },
flags: { [string]: any },
diagnostics: { any },
}command is nil when nothing matched. diagnostics carries the same shapes the parsing layer produces, each with a kind, a message and a source range, enough to underline the offending span.
StartOptions
type StartOptions = {
logger: Log.Logger?,
serializer: any?,
consumerTypes: Instance?,
clientCommands: Instance?,
}Reach it through Client.Mount, not through PlayerGui
The bundle is created at runtime and destroyed when access is revoked, so its path is not a stable address to require. See Custom Interfaces.