Creating Your Bot Files
Welcome! We're now starting to create code for your bot. We already have config.json and .env, and we've set up version control with git.
Creating index.js
javascript
// Import Client from yurba.js
const { Client } = require("yurba.js");
// Load config
const config = require('./config.json');
// Load `.env`
require('dotenv').config()
// Create client (bot) with your token and prefix
const client = new Client(process.env.YURBA_TOKEN, {prefix: config.prefix});
// Register first command - ping
client.registerCommand('ping', {}, (message, args) => {
message.reply(`pong!, ${message.Author.Name}`);
});
// First event - ready
// When the bot starts, it will log 'Ready!' to the console
client.once('ready', () => {
console.log('Ready!');
});
// Initialize the bot (start it)
client.init();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
json
{
"prefix": "/"
}
.env
YURBA_TOKEN=YOUR-TOKEN-HERE
json
{
"name": "my-bot",
"version": "0.0.1",
"description": "bot for guide",
"keywords": [
"bot",
"yurbajs",
"guide-bot"
],
"license": "ISC",
"author": "RastGame",
"type": "commonjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"dotenv": "^17.2.0",
"yurba.js": "^0.1.9"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Add start script
json
{
"name": "my-bot",
"version": "0.0.1",
"description": "bot for guide",
"keywords": [
"bot",
"yurbajs",
"guide-bot"
],
"license": "ISC",
"author": "RastGame",
"type": "commonjs",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"dotenv": "^17.2.0",
"yurba.js": "^0.1.9"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Start the bot
bash
npm start
bash
yarn start
bash
pnpm start
bash
bun start
After starting, you should see something like this:
console
λ ~/Projects/yurbajs/examples/guide-bot main* ❯❯ pnpm start
> my-bot@0.0.1 start /Projects/yurbajs/examples/guide-bot
> node index.js
[dotenv@17.2.0] injecting env (1) from .env (tip: ⚙️ enable debug logging with { debug: true })
Ready!
Let's execute our first command /ping

First achievement!
Creating your bot's first command