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 --pluginNote: 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-pluginNote: 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 --watchBuilding the Plugin
Robo.js includes a built-in compiler to package your plugin for distribution:
robo build pluginThis 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 publishYour 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.
import type { StartContext } from 'robo.js'
export default async (context: StartContext) => {
const { pluginConfig, logger } = context
logger.info('My plugin started!')
}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.
