LogoRobo.js

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.

Install @robojs/mock with:

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@next

Start in mock mode:

npx robo dev --mock

You 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

FocusThe full Stage UI layout with a bot responding to a user messageZoom100%NotesShow a realistic session: a user has sent a message or slash command, and the bot has replied. Include the server list, channel list, message area, member list, and the bottom bar with playback controls and status indicators.

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:

__tests__/ping.test.ts
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') } }
})
__tests__/ping.test.js
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 test

You 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:

FeatureSupport
Gateway WebSocket (real-time events)Full v10 protocol
REST API150+ endpoints
IntentsFiltering and privileged intent enforcement
PermissionsRole hierarchy, channel overwrites
Voice GatewayConnection handshake (no audio)
Rate LimitsConfigurable enforcement
Activity Proxy / Embedded App SDKRPC 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.

Next Steps

On this page