@robojs/discordjs
Discord.js integration for slash commands, events, context menus, middleware, and client management.
The core Discord plugin for Robo.js. It manages the Discord.js client lifecycle, routes slash commands and events through the file system, handles context menus and middleware, auto-defers interactions with Sage mode, infers gateway intents, aggregates permissions, and registers commands with Discord's API.
Features
Slash Commands
File-based routing with type-safe options
Events
Gateway event handlers with frequency control
Embeds
Rich embedded messages with fields and images
Components
Buttons, select menus, and interactive elements
Sage Mode
Automatic defer and error handling
Intent Inference
Auto-detect required gateway intents
Namespace Controllers
Programmatic access to all handlers
Command Registration
Hash-cached registration with retry
Installation
npx robo add @robojs/discordjs@nextOr scaffold a new project with the plugin already wired up:
npx create-robo@next my-bot -p @robojs/discordjs@nextSet DISCORD_TOKEN and DISCORD_CLIENT_ID in your .env file. These are required for the bot to connect to Discord.
DISCORD_TOKEN="your-bot-token"
DISCORD_CLIENT_ID="your-client-id"Quick start
Create a file at src/commands/ping.ts and export a default function:
import type { ChatInputCommandInteraction } from 'discord.js'
export default (interaction: ChatInputCommandInteraction) => {
return 'Pong!'
}export default (interaction) => {
return 'Pong!'
}Run npx robo dev and type /ping in Discord. That's it -- Robo handles registration, deferral, and replies automatically.
Looking for tutorials on building Discord bots? Check out the Bot guides for step-by-step walkthroughs.
Next steps
Configuration
Plugin options, client settings, and environment variables.
Lifecycle
Startup sequence, client timeline, and lifecycle hooks.
Commands
Slash command routing, options, and type-safe configs.
Embeds
Rich embedded messages with fields and images.
Components
Buttons, select menus, and interactive elements.
Sage mode
Automatic defer, error handling, and ephemeral replies.
