API reference
Exported functions, constants, and types from @robojs/dev.
The plugin exports utilities you can use directly in your code. Import them from @robojs/dev.
import { DEBUG_MODE, sendDebugError, printErrorResponse, devLogger } from '@robojs/dev'import { DEBUG_MODE, sendDebugError, printErrorResponse, devLogger } from '@robojs/dev'DEBUG_MODE
const DEBUG_MODE: booleanconst DEBUG_MODE: booleanA constant that is true when the Robo is running in development mode (robo dev). Evaluated once at import time using Mode.isDev() from Robo.
import { DEBUG_MODE } from '@robojs/dev'
if (DEBUG_MODE) {
// Only runs during development
devLogger.info('Debug mode is active')
}import { DEBUG_MODE } from '@robojs/dev'
if (DEBUG_MODE) {
// Only runs during development
devLogger.info('Debug mode is active')
}sendDebugError
async function sendDebugError(error: unknown): Promise<boolean>async function sendDebugError(error): Promise<boolean>Sends an error to the configured debug Discord channel as a rich embed with Dismiss and Restart buttons.
Parameters:
Prop
Type
Returns: true if the error was sent successfully, false otherwise.
The function returns false without throwing in these cases:
- Not in development mode (
DEBUG_MODEisfalse) - No debug channel configured (neither config nor env var)
- Discord client not available or not ready
- Channel not found or not a text channel
- Message send fails
import { sendDebugError } from '@robojs/dev'
try {
await riskyOperation()
} catch (error) {
const sent = await sendDebugError(error)
if (!sent) {
console.error('Could not forward error to Discord:', error)
}
}import { sendDebugError } from '@robojs/dev'
try {
await riskyOperation()
} catch (error) {
const sent = await sendDebugError(error)
if (!sent) {
console.error('Could not forward error to Discord:', error)
}
}handleDebugButton
async function handleDebugButton(interaction: ButtonInteraction): Promise<boolean>async function handleDebugButton(interaction): Promise<boolean>Handles button interactions from debug error embeds. Checks if the button's customId starts with __robo_debug_ and processes it.
Parameters:
Prop
Type
Returns: true if the button was a debug button and was handled, false otherwise.
Two actions are supported:
- Dismiss (
__robo_debug_dismiss) — Deletes the error message - Restart (
__robo_debug_restart) — Replies with "Restarting..." then triggers a process restart
The plugin already registers an interactionCreate event handler that calls this function automatically. Use this directly only if you need custom button handling logic.
import { handleDebugButton } from '@robojs/dev'
// In a custom interaction handler
if (interaction.isButton()) {
const handled = await handleDebugButton(interaction)
if (handled) return
// Handle other buttons...
}import { handleDebugButton } from '@robojs/dev'
// In a custom interaction handler
if (interaction.isButton()) {
const handled = await handleDebugButton(interaction)
if (handled) return
// Handle other buttons...
}printErrorResponse
async function printErrorResponse(
error: unknown,
interaction: CommandInteraction | Message | ButtonInteraction
): Promise<void>async function printErrorResponse(
error: unknown,
interaction: CommandInteraction | Message | ButtonInteraction
): Promise<void>Sends an error as a red embed reply. Handles all interaction states automatically.
Parameters:
Prop
Type
The function determines the best reply method based on the interaction state:
| State | Method |
|---|---|
Message object | message.reply() |
| Deferred interaction | editReply() |
| Already replied | followUp() (ephemeral) |
| Fresh interaction | reply() (ephemeral) |
Error messages are truncated to 4000 characters for Discord embed limits.
import { printErrorResponse } from '@robojs/dev'
export default async function (interaction) {
try {
await someOperation()
} catch (error) {
await printErrorResponse(error, interaction)
}
}import { printErrorResponse } from '@robojs/dev'
export default async function (interaction) {
try {
await someOperation()
} catch (error) {
await printErrorResponse(error, interaction)
}
}devLogger
const devLogger: Loggerconst devLogger: LoggerThe plugin's forked logger instance, created with logger.fork('dev'). All log messages are prefixed with the dev namespace.
import { devLogger } from '@robojs/dev'
devLogger.info('Something happened')
devLogger.debug('Detailed info:', data)import { devLogger } from '@robojs/dev'
devLogger.info('Something happened')
devLogger.debug('Detailed info:', data)DevPluginConfig
import type { DevPluginConfig } from '@robojs/dev'TypeScript interface for the plugin's configuration options.
interface DevPluginConfig {
debugChannelId?: string
errorPingRoleId?: string
commands?: boolean
enabledModes?: string[]
errorForwarding?: boolean
}Prop
Type
Use this type for autocomplete when writing plugin config files:
/** @type {import('@robojs/dev').DevPluginConfig} */
export default {
debugChannelId: '1234567890123456789'
}/** @type {import('@robojs/dev').DevPluginConfig} */
export default {
debugChannelId: '1234567890123456789'
}