Command execution
Natural language routing to your Robo's slash commands.
The AI can execute your Robo's slash commands via natural language. When a user asks "ban user X for spamming", the AI maps this to your /ban command, executes it with the correct parameters, and reports the result back conversationally.
Configuration
Control which commands are exposed to the AI as tools:
export default {
commands: true
}export default {
commands: true
}Prop
Type
Whitelisting specific commands:
export default {
commands: ['ban', 'kick', 'ai log']
}export default {
commands: ['ban', 'kick', 'ai log']
}How it works
The pipeline from natural language to command execution:
- During
engine.init(), the plugin reads all Robo portal commands viaportal.getByType('discord:commands'). - Commands are converted to OpenAI function definitions with JSON schema parameters.
- When the AI decides to invoke a command, a tool call is extracted from the response.
scheduleToolExecution()queues the tool call.- A mock Discord interaction is created with the correct parameters.
- The command handler runs with this mock interaction.
- Results are serialized into tool digests.
- Tool digests are fed back into the next AI turn so the AI can formulate a natural response.
This means your existing slash commands work as AI tools without any modifications. The AI sees them as callable functions with typed parameters.
Permission checks
The system respects Discord's permission model:
- DM permissions are checked before execution.
- Role-based permissions are enforced.
- The AI cannot override Discord's permission settings.
Keep your slash command permissions in sync with the behavior you want from AI-driven execution. If a user doesn't have permission to run /ban directly, the AI won't run it on their behalf either.
Sage deferral
Long-running commands are handled automatically to prevent interaction timeouts:
- Auto-defers after
deferBuffermilliseconds (default 3000). - Background tasks show typing indicators, refreshed every 7 seconds.
- Deferred notices inform users when tasks are still in progress.
The defer buffer prevents premature deferral for fast commands while still catching slow ones before Discord's 3-second interaction timeout.
Background tasks
When commands take time to complete, the plugin tracks them per channel:
import { AI } from '@robojs/ai'
// Check active tasks in a channel
const tasks = AI.getActiveTasks(channelId)import { AI } from '@robojs/ai'
// Check active tasks in a channel
const tasks = AI.getActiveTasks(channelId)The lifecycle of a background task:
registerBackgroundTask()tracks the active task for the channel.- Typing indicators loop until the task completes.
buildDeferredNotice()generates a user-facing placeholder message.completeBackgroundTask()cleans up when the command finishes.
Tool digests
After a command executes, results flow back to the AI:
- Results are wrapped in
ToolDigestobjects. - Digests are queued per channel.
withTaskContext()injects active task context into the AI's system prompt.- The AI receives the command output and formulates a natural language response.
This means the AI doesn't just run commands silently. It reports what happened, what the result was, and can answer follow-up questions about the operation.
