Configuration
Plugin options, client settings, and environment variables for @robojs/discordjs.
The Discord plugin is configured through a file at config/plugins/robojs/discordjs.mjs (or .ts). You only need to specify the options you want to change.
import type { DiscordConfig } from '@robojs/discordjs'
export default {
sage: {
defer: true,
ephemeral: false
}
} satisfies DiscordConfigexport default {
sage: {
defer: true,
ephemeral: false
}
}Plugin options
Prop
Type
Client options
Configure the Discord.js Client constructor. The most common use is setting gateway intents:
import { GatewayIntentBits } from 'discord.js'
import type { DiscordConfig } from '@robojs/discordjs'
export default {
clientOptions: {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
}
} satisfies DiscordConfigimport { GatewayIntentBits } from 'discord.js'
export default {
clientOptions: {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
}
}The plugin automatically infers required intents from your registered events. You only need to set clientOptions.intents for privileged intents or when you want explicit control. See Intents & permissions for details.
Command defaults
Set defaults applied to all commands and context menus. Individual commands can override these values.
Prop
Type
Prefix configuration
Configure how prefix commands are triggered. See Prefix Commands for full documentation.
Prop
Type
Timeout configuration
Prop
Type
The defer buffer timing follows a priority chain: a command-level sage.deferBuffer takes highest priority, then the plugin-level sage.deferBuffer, then timeouts.commandDeferral. If none are set, the default is 250ms.
Environment variables
| Variable | Required | Description |
|---|---|---|
DISCORD_TOKEN | Yes | Bot token from the Discord Developer Portal. |
DISCORD_CLIENT_ID | Yes | Application client ID from the Discord Developer Portal. |
DISCORD_CLIENT_SECRET | No | Application client secret (needed for OAuth2 flows). |
DISCORD_GUILD_ID | No | Register commands as guild commands for this server (faster updates during development). |
DISCORD_REST_API | No | Custom REST API base URL (used with @robojs/mock for testing). |
DISCORD_FORCE_REGISTER | No | Set to true to force re-register all commands. |
ROBO_MOCK_MODE | No | Set to true to enable mock mode (registers commands at runtime). |
DISCORD_TOKEN="your-bot-token"
DISCORD_CLIENT_ID="your-client-id"Complete config example
import { GatewayIntentBits } from 'discord.js'
import type { DiscordConfig } from '@robojs/discordjs'
export default {
autoRegisterCommands: true,
clientOptions: {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent
]
},
defaults: {
contexts: ['Guild', 'BotDM'],
integrationTypes: ['GuildInstall'],
defaultMemberPermissions: undefined
},
prefix: {
value: '!',
caseSensitive: false
},
sage: {
defer: true,
deferBuffer: 250,
ephemeral: false,
errorReplies: true
},
testServers: ['123456789012345678'],
timeouts: {
autocomplete: 3000,
commandDeferral: 250,
commandRegistration: 30000
}
} satisfies DiscordConfigimport { GatewayIntentBits } from 'discord.js'
export default {
autoRegisterCommands: true,
clientOptions: {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent
]
},
defaults: {
contexts: ['Guild', 'BotDM'],
integrationTypes: ['GuildInstall'],
defaultMemberPermissions: undefined
},
prefix: {
value: '!',
caseSensitive: false
},
sage: {
defer: true,
deferBuffer: 250,
ephemeral: false,
errorReplies: true
},
testServers: ['123456789012345678'],
timeouts: {
autocomplete: 3000,
commandDeferral: 250,
commandRegistration: 30000
}
}Client access
You can access the underlying Discord.js Client instance anywhere in your project using exported helpers:
import { getClient, hasClient } from '@robojs/discordjs'
// Check if client is available before accessing
if (hasClient()) {
const client = getClient()
// Use the Discord.js client
}getClient()returns the Discord.jsClientinstance.hasClient()returns a boolean indicating whether the client has been initialized.
Type re-exports
The plugin re-exports common Discord.js types for convenience. However, prefer importing these directly from discord.js:
| Type | Description |
|---|---|
AutocompleteInteraction | Autocomplete interaction for command options |
ChatInputCommandInteraction | Slash command interaction |
Client | Discord.js client instance |
ClientEvents | Map of all client event names to their argument types |
ClientOptions | Discord.js Client constructor options |
ContextMenuCommandInteraction | Base context menu interaction |
Guild | Discord guild (server) |
GuildMember | Guild member |
Interaction | Base interaction type |
Message | Discord message |
MessageContextMenuCommandInteraction | Message context menu interaction |
Role | Discord role |
TextChannel | Text channel |
User | Discord user |
UserContextMenuCommandInteraction | User context menu interaction |
VoiceChannel | Voice channel |
Plugin-specific types like CommandConfig, EventConfig, MiddlewareData, and DiscordConfig should always be imported from @robojs/discordjs.
Logger
The plugin exposes a forked logger for Discord-specific logging:
import { discordLogger } from '@robojs/discordjs'
discordLogger.info('Custom Discord log message')