Portal
Access and modify your Robo's internals on the fly using the Portal API.
The Portal API provides runtime access to your Robo's registered commands, events, context commands, middleware, and modules. You can inspect what is registered and enable or disable modules without modifying files.
Enabling and Disabling Modules
Toggle modules at runtime. When disabled, the module's commands and events stop responding as if they do not exist.
import { portal } from 'robo.js'
// Disable a module
portal.module('admin').setEnabled(false)import { portal } from 'robo.js'
// Disable a module
portal.module('admin').setEnabled(false)Check whether a module is currently enabled:
const isAdminEnabled = portal.module('admin').isEnabled()const isAdminEnabled = portal.module('admin').isEnabled()Inspecting Registered Handlers
Access registered handlers through namespaces. For example, Discord handlers live under the discord namespace:
// Access all handlers as a flat list
const allHandlers = portal.all()
// Access handlers by type string
const commands = portal.getByType('discord:commands')
const events = portal.getByType('discord:events')// Access all handlers as a flat list
const allHandlers = portal.all()
// Access handlers by type string
const commands = portal.getByType('discord:commands')
const events = portal.getByType('discord:events')Note: Changes made through the Portal are in-memory only. They persist for the current session but reset when the process restarts.
Persisting Changes
To preserve module states across restarts, store them in a database and restore them at startup:
import { portal } from 'robo.js'
export default async function () {
const database = ... // load your database
async function updateModuleStates() {
const moduleStates = await database.getModuleStates()
for (const [moduleName, isEnabled] of Object.entries(moduleStates)) {
portal.module(moduleName).setEnabled(isEnabled)
}
}
// Restore module states at startup
await updateModuleStates()
// Poll for changes periodically
setInterval(updateModuleStates, 10 * 60 * 1000)
}import { portal } from 'robo.js'
export default async function () {
const database = ... // load your database
async function updateModuleStates() {
const moduleStates = await database.getModuleStates()
for (const [moduleName, isEnabled] of Object.entries(moduleStates)) {
portal.module(moduleName).setEnabled(isEnabled)
}
}
// Restore module states at startup
await updateModuleStates()
// Poll for changes periodically
setInterval(updateModuleStates, 10 * 60 * 1000)
}This pattern enables building admin interfaces that toggle modules through a database, with changes taking effect at the next poll interval.
