Створення файлів вашого бота
Вітаємо! Тепер ми починаємо створювати код для вашого бота. У нас вже є config.json та .env, і ми налаштували контроль версій з git.
Створення 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({prefix: config.prefix});
// Register first command - ping
client.commands.register('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(process.env.YURBA_TOKEN);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-HEREjson
{
"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": "^1.0.0-next.15"
}
}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
Додавання start скрипта
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": "^1.0.0-next.15"
}
}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
Запуск бота
bash
npm startbash
yarn startbash
pnpm startbash
bun startПісля запуску ви повинні побачити щось подібне:
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!Давайте виконаємо нашу першу команду /ping

Перше досягнення!
Створення першої команди вашого бота