Skip to main content

✨ Getting Started with Discord Bots

Robo.js makes building Discord.js bots as easy as putting certain files in the right place. Want to create a command? Just make a file in the /src/commands directory. Events? Create files in /src/events. It's that simple!

Robo.js does not replace Discord.js!

Instead, it simplifies coding by handling boilerplate. You still have all of Discord.js!

Got an existing bot? Check out the Migration Guide for how to use existing code with Robo.js.

Quick Start

Ready to start your adventure? Try Create Robo in your terminal:

npx create-robo <projectName> -k bot

This will spawn a new Robo.js project ready to use as a Discord Bot. We call these Robos.

File Structure

Discord bots built with Robo.js follow the following file structure:

  • /src/commands: Slash commands. Can be nested for subcommands or subcommand groups.
  • /src/context: Context commands for either /user or /message.
  • /src/events: Discord events. Can be nested for grouped events.

Basic Example

/src
├── /commands
│ └── ping.js
└── /events
└── messageCreate.js

The above is used to create:

  • /ping command.
  • messageCreate event.

Advanced Example

/src
├── /commands
│ ├── ping.js
│ ├── /ban
│ │ └── user.js
│ └── /settings
│ └── /update
│ └── something.js
├── /context
│ ├── /user
│ │ └── Audit.js
│ └── /message
│ └── Report.js
└── /events
├── ready.js
└── /messageCreate
├── dm.js
└── hello.js

The above is used to create:

  • /ping command.
  • /ban user subcommand.
  • /settings update something subcommand group.
  • Audit user context command.
  • Report message context command.
  • ready event.
  • dm and hello grouped messageCreate events.

Modules

For larger projects, you can use modules to group similar functionality together as if they were mini-projects within your main project. Each module follows the same file structure.

Slash Commands

Slash commands in Robo.js are straightforward. Just create a file in the commands directory, and the name of the file becomes the name of the command. Easy peasy, right? You can even nest commands for those extra spicy subcommands!

Example Usage

Creating a command is as easy as exporting a default function from a file in the /src/commands directory.

/src/commands/ping.js
export default () => {
return 'Pong!'
}

To learn more about commands and their full potential, head over to the Commands Section.

Registration

It's automatic! Robo.js will register command changes for you whenever you build or dev your project. So just sit back, relax, and code away!

If you run into any issues or don't see your changes, you can always run build with the --force flag. This will force Robo.js to clean up and re-register all commands.

Context Commands

Ever right clicked on someone's profile or a message and seen an "Apps" section? Those are context commands!

Creating and registering context commands in Robo.js is no different from regular commands. The /context directory can have two subdirectories: /user and /message. Just like commands, the name of the file becomes the name of the context command.

Event Listeners

Listening to events using Robo.js again follows the same file structure. Create a file in the events directory, and the name of the file becomes the Discord event you're listening to. Noticing a pattern here?

Example Usage

Registering an event listener is as simple as creating a file in the /src/events directory.

/src/events/messageCreate.js
export default (message) => {
if (message.content.includes('hello')) {
message.channel.send('Hello there!')
}
}

Your default export is the equivalent of client.on('messageCreate', (message) => {}) in Discord.js. The same exact parameters are passed to your event listener function.

Sage Mode

Sage Mode is a powerful feature in Robo.js that simplifies interaction handling. It operates behind the scenes, automatically simplifying interaction handling and providing smart error replies to make debugging easier.

Plugin Power Ups

Robo Plugins are special. They let you add features to your Robo with one command.

npx robo add @robojs/ai @robojs/moderation

Plugins integrate seamlessly thanks to the Robo File Structure. What's more, anyone can create a plugin.

Community

Join our server to chat with other developers, ask questions, and share your projects.

Our very own Robo, Sage, is there to answer any questions about Robo.js, Discord.js, and more.

AI Plugin

Sage is powered by @robojs/ai

Learn More

Robo.js has a lot to offer for such a tiny framework with zero dependencies.

Robo.js Logo

MIT © 2024 Robo.js By WavePlay