LogoRobo.js

Creating Plugins

Learn how to create your own plugins for Robo.js.

Developing a Robo plugin works the same way as developing features for a Robo.

To create a new plugin project, run the following command:

npx create-robo@next your-awesome-robo-plugin --plugin

Note: The --plugin flag is required to create a plugin project instead of a standard Robo.

Testing Your Plugin

To test your plugin during development, install it from your local directory in a test Robo project. Navigate to your test Robo project's directory and run:

robo add /path/to/your-awesome-robo-plugin

Note: On Windows, the path may look like C:\path\to\your-awesome-robo-plugin.

Replace /path/to/your-awesome-robo-plugin with the actual path to your plugin's directory. Build your plugin between changes using the robo build plugin command.

Use the --watch flag to automatically rebuild your plugin when changes are detected. If your test Robo is also running in dev mode, it will auto-reload when your plugin is rebuilt:

robo build plugin --watch

Building the Plugin

Robo.js includes a built-in compiler to package your plugin for distribution:

robo build plugin

This compiles your plugin and prepares it for publishing to npm.

Publishing to npm

Once you have built your plugin using robo build plugin, you can publish it to npm. Make sure you have set up your npm account and are logged in through the CLI:

npm publish

Your plugin is now available on npm for other Robo.js users to install.

Note: Keep sensitive information out of your plugin. Avoid including .env files or similar data that should not be shared with other users.

Lifecycle Hooks

Plugins can hook into the Robo.js lifecycle by creating files in src/robo/. These hooks let your plugin run code at startup, shutdown, or during builds.

start.tsRuns on startup
stop.tsRuns on shutdown
prepare.tsInitialize resources
src/robo/start.ts
import type { StartContext } from 'robo.js'

export default async (context: StartContext) => {
	const { pluginConfig, logger } = context
	logger.info('My plugin started!')
}
src/robo/start.js
export default async (context) => {
	const { pluginConfig, logger } = context
	logger.info('My plugin started!')
}

Plugins can also define route definitions to register custom file conventions (like how @robojs/discordjs makes src/commands/ work).

See Lifecycle Hooks for all available hooks and their execution order.

Want your plugin to work great with AI coding tools? Learn how to create skills for your plugin.

Next Steps

On this page