LogoRobo.js

Configuration

Configure your Discord Activity project

This page is the central reference for all configuration in a Discord Activity project. Other pages link here rather than duplicating config details.

server.tsServer plugin config
sync.tsSync plugin config
patch.tsPatch plugin config
robo.mjsMain config
vite.mjsVite config
.envSecrets

VS Code file explorer showing the config directory structure with robo.mjs, vite.mjs, and config/plugins/robojs containing server.ts, sync.ts, and patch.ts

FocusThe config directory structure showing all configuration filesZoom100%NotesShow VS Code file explorer with config/ expanded: robo.mjs, vite.mjs, plugins/robojs/ with server.ts, sync.ts, patch.ts. Also .env in root. Optionally have one config file open.

Robo Configuration

The main Robo config file is config/robo.mjs (or .ts). This controls the Robo.js runtime, plugins, and experimental features.

config/robo.mjs
export default {
  // Enable experimental features
  experimental: {
    disableBot: true // Activities don't need the bot gateway connection
  }
}
config/robo.mjs
export default {
  // Enable experimental features
  experimental: {
    disableBot: true // Activities don't need the bot gateway connection
  }
}

Activity projects use the --tunnel (-t) flag on robo dev to start a Cloudflare Tunnel during development. The scaffolded dev script includes this flag by default. For stable tunnel URLs, configure Cloudflare credentials in the @robojs/server plugin config's tunnel section. See Tunnels for details.

Vite Configuration

The config/vite.mjs file configures the Vite build tool. Activity projects include the React plugin and the Discord proxy plugin by default.

config/vite.mjs
import { DiscordProxy } from '@robojs/patch'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [react(), DiscordProxy.Vite()],
  server: {
    allowedHosts: true
  }
})
config/vite.mjs
import { DiscordProxy } from '@robojs/patch'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [react(), DiscordProxy.Vite()],
  server: {
    allowedHosts: true
  }
})

DiscordProxy.Vite() must remain in the plugins array. Removing it will break network requests when running inside Discord.

Server Configuration

Configure @robojs/server in config/plugins/robojs/server.ts:

config/plugins/robojs/server.ts
export default {
  port: 3000,
  cors: true
}
config/plugins/robojs/server.js
export default {
  port: 3000,
  cors: true
}
OptionTypeDefaultDescription
portnumber3000Server port. Overridden by the PORT env variable.
corsbooleanfalseEnable CORS headers on all API routes.
prefixstring/apiRoute prefix for file-based API endpoints.

Environment Variables

Store these in a .env file in your project root. Robo.js loads them automatically at startup.

VariableRequiredDescription
DISCORD_CLIENT_IDYesApplication ID (used by backend / process.env)
VITE_DISCORD_CLIENT_IDYesSame Application ID (used by frontend / import.meta.env). Must match DISCORD_CLIENT_ID.
DISCORD_CLIENT_SECRETYesOAuth2 client secret from the Developer Portal
DISCORD_TOKENNoBot token. When set, @robojs/patch auto-creates the entry point command.
PORTNoOverrides the server port from plugin config

Vite only exposes variables prefixed with VITE_ to client-side code. That is why both DISCORD_CLIENT_ID and VITE_DISCORD_CLIENT_ID exist — they hold the same value but are read by different environments.

Plugin Configuration

Plugins are configured via files in config/plugins/. The file path mirrors the plugin's package name: the @ scope is dropped and / becomes a directory. For example, @robojs/server becomes config/plugins/robojs/server.ts.

PluginConfig file
@robojs/serverconfig/plugins/robojs/server.ts
@robojs/syncconfig/plugins/robojs/sync.ts
@robojs/patchconfig/plugins/robojs/patch.ts

Each file default-exports an options object specific to that plugin.

SyncContextProvider Options

When using @robojs/sync for multiplayer, wrap your app in SyncContextProvider. See the Sync API reference for the full API.

PropTypeDefaultDescription
loadingScreenReactNodenullComponent shown while the WebSocket connection is being established
clientDataunknownundefinedMetadata attached to this client, visible to other connected clients

Next Steps

On this page