LogoRobo.js

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.

discordjs.tsPlugin config
config/plugins/robojs/discordjs.ts
import type { DiscordConfig } from '@robojs/discordjs'

export default {
	sage: {
		defer: true,
		ephemeral: false
	}
} satisfies DiscordConfig
config/plugins/robojs/discordjs.mjs
export 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:

config/plugins/robojs/discordjs.ts
import { GatewayIntentBits } from 'discord.js'
import type { DiscordConfig } from '@robojs/discordjs'

export default {
	clientOptions: {
		intents: [
			GatewayIntentBits.Guilds,
			GatewayIntentBits.GuildMessages,
			GatewayIntentBits.MessageContent
		]
	}
} satisfies DiscordConfig
config/plugins/robojs/discordjs.mjs
import { 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

VariableRequiredDescription
DISCORD_TOKENYesBot token from the Discord Developer Portal.
DISCORD_CLIENT_IDYesApplication client ID from the Discord Developer Portal.
DISCORD_CLIENT_SECRETNoApplication client secret (needed for OAuth2 flows).
DISCORD_GUILD_IDNoRegister commands as guild commands for this server (faster updates during development).
DISCORD_REST_APINoCustom REST API base URL (used with @robojs/mock for testing).
DISCORD_FORCE_REGISTERNoSet to true to force re-register all commands.
ROBO_MOCK_MODENoSet to true to enable mock mode (registers commands at runtime).
.env
DISCORD_TOKEN="your-bot-token"
DISCORD_CLIENT_ID="your-client-id"

Complete config example

config/plugins/robojs/discordjs.ts
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 DiscordConfig
config/plugins/robojs/discordjs.mjs
import { 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.js Client instance.
  • 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:

TypeDescription
AutocompleteInteractionAutocomplete interaction for command options
ChatInputCommandInteractionSlash command interaction
ClientDiscord.js client instance
ClientEventsMap of all client event names to their argument types
ClientOptionsDiscord.js Client constructor options
ContextMenuCommandInteractionBase context menu interaction
GuildDiscord guild (server)
GuildMemberGuild member
InteractionBase interaction type
MessageDiscord message
MessageContextMenuCommandInteractionMessage context menu interaction
RoleDiscord role
TextChannelText channel
UserDiscord user
UserContextMenuCommandInteractionUser context menu interaction
VoiceChannelVoice 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')

Next steps

On this page