Skip to main content

✨ Discord Bots Overview

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 the process of building Discord bots by taking care of boilerplate code. You still have access to the full Discord.js API and existing code is still compatible!

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

Getting Started

Creating a Discord bot with Robo.js is as easy as running one command.

npx create-robo <projectName> --kit bot

This will walk you through setting up your project and installing the necessary dependencies. Once selected, you can run and start developing your Discord bot right away!

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.

Sage is also the name of our Discord bot that can answer any questions you have about Robo.js. Come say hi!

AI Plugin

Sage is powered by @robojs/ai and can answer your questions about Robo.js, Discord Activities, and more.

Robo.js Logo

MIT © 2024 Robo.js By WavePlay