LogoRobo.js

@robojs/discordjs

Discord.js integration for slash commands, events, context menus, middleware, and client management.

Install @robojs/discordjs with:

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

Or scaffold a new project with the plugin already wired up:

npx create-robo@next my-bot -p @robojs/discordjs@next

Set DISCORD_TOKEN and DISCORD_CLIENT_ID in your .env file. These are required for the bot to connect to Discord.

.env
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:

ping.ts/ping
src/commands/ping.ts
import type { ChatInputCommandInteraction } from 'discord.js'

export default (interaction: ChatInputCommandInteraction) => {
	return 'Pong!'
}
src/commands/ping.js
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

On this page