Skip to content

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:

luau
-- 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)
end

Every 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

luau
Api.isReady(): boolean

Whether the bundle has connected.

Api.run

luau
Api.run(text: string): Result

Dispatches 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

luau
Api.parse(text: string): ParseResult

Parses 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

luau
Api.queryLogs(query: Query?): LogPage

Asks the server for a page of log records. Yields until it answers.

luau
local page = Api.queryLogs({ stream = "moderation", search = "bob", days = 7, limit = 40 })
FieldMeaning
stream"general" or "moderation"; defaults to "general"
searchfree text matched across names, ids, commands, actions and reasons
dayshow far back to look
limitpage size
cursorthe 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

luau
Api.getCommands(): { Command }

The commands in this player's manifest.

Api.getCommand

luau
Api.getCommand(path: { string } | string): Command?

One command by path or name, or nil.

Api.getType

luau
Api.getType(name: string): AnyArgType?

Resolves an argument type by name.

Api.getSettings

luau
Api.getSettings(): { [string]: any }

The client settings the server sent: the Client config table.

Api.setConfirmHandler

luau
Api.setConfirmHandler(handler: ((prompt: string) -> boolean)?): ()

Answers destructive confirmations. With no handler installed the answer is no, so destructive commands fail closed.

luau
Api.setConfirmHandler(function(prompt)
	return showDialog(prompt)
end)

Api.toggle

luau
Api.toggle(visible: boolean?): boolean

Opens, 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.

luau
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

luau
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

luau
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

luau
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

luau
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

luau
Api.stop(): ()

Properties

Api.suggestions

A SuggestionCache for autocomplete.

Types

Result

luau
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

luau
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

luau
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

luau
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.

Released under the MIT Licence.