๐ฐ Beginner Guide
Despite how simple Robo.js make things, it can be a bit overwhelming at first. There's a lot to take in, but don't worry! This guide will help you get started with the basics of creating a Discord Bot.
Before we get started, make sure you have Node.js installed alongside VS Code or your favorite code editor.
Runningโ
Once you've created a Robo, you can run it in your Terminal.
npm run dev
Make sure your Credentials are set up correctly first.
Slash Commandsโ
Creating a Slash Command is as easy as creating files.
Let's say you want a new /hello
command. Just create a file in the /src/commands
directory named hello.js
and export a default function that returns something.
- Javascript
- Typescript
export default () => {
return 'Hello World!'
}
import type { CommandResult } from 'robo.js'
export default (): CommandResult => {
return 'Hello World!'
}
Your /hello
command is now ready to use! Robo.js takes care of registration for you.
Miss your interaction object? Don't worry, it's still there!
- Javascript
- Typescript
export default (interaction) => {
interaction.reply('Hello World!')
}
import type { ChatInputCommandInteraction } from 'discord.js'
import type { CommandResult } from 'robo.js'
export default (interaction: ChatInputCommandInteraction): CommandResult => {
interaction.reply('Hello World!')
}
This is just the beginning. Nest folders to create subcommands, make your export async to defer, define options, and more.
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.
- Javascript
- Typescript
export default (message) => {
if (message.content.includes('hello')) {
message.channel.send('Hello there!')
}
}
import type { Message } from 'discord.js'
export default (message: 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.