Mock Server Overview
Test Discord bots and activities locally with a simulated Discord server.
@robojs/mock
Test Discord bots and activities locally with a simulated Discord server.
Testing a Discord bot or activity usually means deploying it, switching to Discord, and clicking through interactions manually. Mock Server eliminates that loop.
Mock Server simulates Discord's API and Embedded App SDK on your machine. Your bot connects to it instead of Discord, and your activity runs against a local proxy instead of *.discordsays.com. Test slash commands, buttons, modals, SDK commands, and complex flows without waiting for Discord's servers.
Quick Start
Add the plugin to your Robo:
npx robo add @robojs/mock@nextStart in mock mode:
npx robo dev --mockYou should see the mock server start in your terminal, followed by a browser window opening Stage UI. The terminal shows a session ID and the Stage URL.
For Discord activities, launch your activity from Stage UI after starting mock mode. The activity loads in an iframe with full Embedded App SDK simulation. See the Testing Activities guide for details.
Stage UI opens automatically in your browser. Send messages, trigger commands, and watch your bot respond in real-time.
Stage UI overview showing the full Discord-like interface with a server list on the left, channel list, a message area in the center with a bot conversation, and a member list on the right, with playback controls and a status bar at the bottom
How to Test
There are three approaches to testing with Mock Server. Pick the one that fits your needs, or combine them:
- Stage UI -- Best for exploring your bot's behavior, debugging issues, and learning how commands and events work. No code needed; just interact with your bot in a Discord-like interface.
- Automated tests -- When you want repeatable, CI-integrated test suites that catch regressions. Write Jest tests that dispatch interactions and assert on bot responses.
- Scenarios -- For complex, shareable test flows defined as JSON documents. Scenarios are version-controlled, reproducible, and can be run through the Control API or Stage UI.
Mock Server is designed for testing Discord bots and Discord activities. If you're new to building with Robo.js, start with those guides first.
Here is a quick taste of what an automated test looks like:
import { createTestSession, dispatchInteraction, expectAction } from '@robojs/mock/testing'
const session = await createTestSession(__filename)
await dispatchInteraction(session.id, {
type: 2, // APPLICATION_COMMAND
data: { name: 'ping', type: 1 }, // CHAT_INPUT
channel_id: session.channels[0].id
})
await expectAction(session.id, {
description: 'Bot should reply with pong',
type: 'interaction_response',
expected: { response_data: { content: expect.stringContaining('Pong') } }
})import { createTestSession, dispatchInteraction, expectAction } from '@robojs/mock/testing'
const session = await createTestSession(__filename)
await dispatchInteraction(session.id, {
type: 2, // APPLICATION_COMMAND
data: { name: 'ping', type: 1 }, // CHAT_INPUT
channel_id: session.channels[0].id
})
await expectAction(session.id, {
description: 'Bot should reply with pong',
type: 'interaction_response',
expected: { response_data: { content: expect.stringContaining('Pong') } }
})Run your tests:
npx robo mock testYou should see the mock server start, your test suite run, and results printed in the terminal with pass/fail indicators.
What Gets Simulated
Mock Server emulates Discord's Gateway (the real-time WebSocket connection, v10 protocol) and REST API:
| Feature | Support |
|---|---|
| Gateway WebSocket (real-time events) | Full v10 protocol |
| REST API | 150+ endpoints |
| Intents | Filtering and privileged intent enforcement |
| Permissions | Role hierarchy, channel overwrites |
| Voice Gateway | Connection handshake (no audio) |
| Rate Limits | Configurable enforcement |
| Activity Proxy / Embedded App SDK | RPC host, auth, IAP, platform signals |
Session Isolation
Each test gets its own session with independent state. Sessions have their own:
- Guilds, channels, and users
- Messages and interactions
- Recorded actions for assertions
This enables parallel test execution without interference.
