create account

🎮 Building my first Discord Bot with NodeJS + Mongo DB by rama-dev

View this thread on: hive.blogpeakd.comecency.com
· @rama-dev ·
$1.28
🎮 Building my first Discord Bot with NodeJS + Mongo DB
![RPG Discord Bot Cover.png](https://files.peakd.com/file/peakd-hive/rama-dev/23w2smzdFYCdFL3GNEptoodGPG9ToVNKR3cTigM2KNny1uMHacowkwWtBjDNDHG5vc2ET.png)

<small><sub>🇪🇸 Versión en español abajo</sub></small>

## <center>Hey Hive!</center>

This weekend I decided to explore a skill I had been curious about for a while: **creating a Discord bot.**

I know many popular bots combine useful features with game mechanics, so I wanted to see how they actually work.

I wasn’t very cautious when choosing the difficulty, and for my very first project, I decided to build… an **RPG bot** 😅

---

### What did I use to build it?

I chose a tech stack I was already familiar with, although I hadn’t used it in a while:

- Node.js as the main engine  
- discord.js v14 to implement the bot  
- MongoDB Atlas to store user progress

If it happens to you: I had a small issue connecting to the database. It turned out to be a problem with the user I was using (created for another DB). I solved it by creating a new one with proper access.

---

### First features

Since this was a pretty ambitious goal, I broke it down into smaller parts and started with:

- Create your character with `/start`  
- View your stats with `/profile`  
- Fight enemies in turn-based battles using `/battle` (costs energy)

The development of these first commands was quite smooth. I hadn’t used Node.js in a while and forgot how much I loved its modular folder structure!

<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tkfFNgHydquNehUdBLR96a1ZPiAtKAqJMUkhckTeqYmB5oGrJ9Ks6wdHA7gpgQ1HJXL.png)
*(A little spoiler here showing features I added later)*</center>

The bot uses `index.js` to start up, listen for commands, and connect to the database.

Inside the `commands` folder are all the bot commands and logic.

The `models` folder contains the `Player` model that defines the data saved to the database.

---

### Let’s see the bot in action!

1. I created my character with `/start`:  
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23uQNRRze3aDoxjS8nfmPPpe8Cn6eNeA1EBV8GCc9vCDtdKTExvrCkfZfDD16oa1sesPz.png)</center>

2. Then checked my stats using `/profile`:  
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tkpMCah7aC7JhkLcL49xM4b428tP7qMpxk5VMwbKSKXbr9f1CyLstfBLWcShrNy33kp.png)</center>
This was the first version. Later, I upgraded the embed to look cleaner and more professional:  
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tbPAj4naDNL15qVai69jdrKdEh5hzdJLLMFfitT4Y2YYHdXojqARfjpC5Q9rDSJXbRR.png)</center>

3. And here’s a battle using `/battle`:  
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tS12kM1go813Fmtt2jmD2VCxdXFqmBMcNKzyXhBjnA9p8q9iZv7FVeT8uViXdPrFiie.png)  
*We fought a slime and won!*</center>

---

### Bonus: Shop & Inventory

Since I had some free time left, I added a shop and inventory system!

<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23wqCQBN9HUi5czw8gAwQjDF3WexVihdzNyP7tFSaVmLt7sVYDnhgBVnYEUom4ceyub88.png)  
![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tknNQUVa7EDbcMwwKfMqxEP4iFLbaTZyNvSpL4Mg8ewhY9Wi1NpwAsSamKMdwT75jt3.png)</center>

---

## Coming Soon

- `/use` command to consume items (potions, buffs, etc.)  
- Cooldowns and daily rewards  
- More items, enemies, and levels  
- Hive integration? 👀

---

I’m super happy with how much I learned and built in just a few days. I’ll keep improving the bot in my spare time and maybe release other prototypes.

If you have any ideas for this bot or other bot projects, feel free to share them in the comments — I’d love to hear your thoughts!

Thanks for reading, and see you in the next post!


---

### <center>🇪🇸 ESPAÑOL</center>

---

## <center>Hola Hive!</center>

Este fin de semana decidí explorar una habilidad que hace rato me daba curiosidad: **crear un bot para Discord.**

Sabía que muchos bots populares combinan funciones útiles con mecánicas de juego, así que decidi ver como funcionan.

No fui muy prudente en cuanto a dificultad del juego y decidi como primer proyecto desarrollar un bot para un juego RPG. 😅

### ¿Qué usé para construirlo?

Elegí un stack que conocía pero no utilizaba hace un tiempo:

- Node.js como motor principal

- discord.js v14 para implementar el bot

- MongoDB Atlas para guardar progreso de los jugadores

Por si les pasa tuve un pequeño problema inicial conectándome a la base de datos, era un problema con el usuario que queria utilizar(era un usuario que habia creado para otra base de datos)  y se soluciono creando uno nuevo.

### Primeras funcionalidades

Ya que me puse un objetivo bastante ambicioso decidi dividirlo un poco y empezar por:

- Creacion del personaje `/start`
- Poder ver tu perfil con tus stats `/profile`
- Poder pelear con algun enemigo en batalla por turnos y consume energia `/battle`

El desarrollo de estos primeros comandos la verdad que fue bastante simple y directo. Hace tiempo que no usaba Node JS y me habia olvidado lo mucho que me gustaba la estructura modular de archivos y carpetas

<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tkfFNgHydquNehUdBLR96a1ZPiAtKAqJMUkhckTeqYmB5oGrJ9Ks6wdHA7gpgQ1HJXL.png)
*(hice un poco de spoiler ya que estoy mostrando cosas que implemente despues)*</center>

el bot utiliza `index.js` que funciona como encendido del bot para escuchar y cargar los comandos y tambien conectarse a la base de datos

luego en la carpeta `commands` tenemos todos los comandos con su logica 

y en la carpeta `models` el modelo de `Player` que funciona como estructura de datos que se guarda en la base de datos

Terminando con los tecnicismos miremos al bot en accion!

1. Cree mi perfil/personaje utilizando el comando `/start`
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23uQNRRze3aDoxjS8nfmPPpe8Cn6eNeA1EBV8GCc9vCDtdKTExvrCkfZfDD16oa1sesPz.png)</center>

2. Luego con el comando `/profile` ya lo pude ver
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tkpMCah7aC7JhkLcL49xM4b428tP7qMpxk5VMwbKSKXbr9f1CyLstfBLWcShrNy33kp.png)</center>
Esta fue la primer version pero luego agregue mas detalles para que se vea mucho mas estetico y profesional
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tbPAj4naDNL15qVai69jdrKdEh5hzdJLLMFfitT4Y2YYHdXojqARfjpC5Q9rDSJXbRR.png)</center>

3. y aca esta como se ve cuando combatis con el comando `/battle`
<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tS12kM1go813Fmtt2jmD2VCxdXFqmBMcNKzyXhBjnA9p8q9iZv7FVeT8uViXdPrFiie.png)
*Combatimos un slime y ganamos!*</center>

### Bonus

Como todavia tenia tiempo libre decidi implementar mas cosas como un mercado y el inventario!

<center>![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23wqCQBN9HUi5czw8gAwQjDF3WexVihdzNyP7tFSaVmLt7sVYDnhgBVnYEUom4ceyub88.png)
![image.png](https://files.peakd.com/file/peakd-hive/rama-dev/23tknNQUVa7EDbcMwwKfMqxEP4iFLbaTZyNvSpL4Mg8ewhY9Wi1NpwAsSamKMdwT75jt3.png)</center>


## Proximamente

- Comando /use: consumir ítems del inventario (pociones, mejoras, etc.)

- Cooldowns y recompensas diarias

- Más ítems, enemigos, niveles

- Integracion con Hive? 👀

Estoy muy contento con lo desarrollado hasta ahora. Voy a seguir mejorando el bot en mi tiempo libre y probablemente haga otros prototipos. Si tienen alguna idea para el bot u otro bot dejenla en los comentarios me encantaria leerlas!

Gracias por leer y nos vemos en el siguiente post!




👍  , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorrama-dev
permlinkbuilding-my-first-discord-bot-with-nodejs--mongo-db
categoryhive-122422
json_metadata"{"app":"peakd/2025.6.1","format":"markdown","description":"A weekend project turned into an RPG game. Next step: Hive integration?","tags":["games","blog","weekend","dev","discord","project","pimp","bro","gamedev","programming"],"users":[],"image":["https://files.peakd.com/file/peakd-hive/rama-dev/23w2smzdFYCdFL3GNEptoodGPG9ToVNKR3cTigM2KNny1uMHacowkwWtBjDNDHG5vc2ET.png","https://files.peakd.com/file/peakd-hive/rama-dev/23tkfFNgHydquNehUdBLR96a1ZPiAtKAqJMUkhckTeqYmB5oGrJ9Ks6wdHA7gpgQ1HJXL.png","https://files.peakd.com/file/peakd-hive/rama-dev/23uQNRRze3aDoxjS8nfmPPpe8Cn6eNeA1EBV8GCc9vCDtdKTExvrCkfZfDD16oa1sesPz.png","https://files.peakd.com/file/peakd-hive/rama-dev/23tkpMCah7aC7JhkLcL49xM4b428tP7qMpxk5VMwbKSKXbr9f1CyLstfBLWcShrNy33kp.png","https://files.peakd.com/file/peakd-hive/rama-dev/23tbPAj4naDNL15qVai69jdrKdEh5hzdJLLMFfitT4Y2YYHdXojqARfjpC5Q9rDSJXbRR.png","https://files.peakd.com/file/peakd-hive/rama-dev/23tS12kM1go813Fmtt2jmD2VCxdXFqmBMcNKzyXhBjnA9p8q9iZv7FVeT8uViXdPrFiie.png","https://files.peakd.com/file/peakd-hive/rama-dev/23wqCQBN9HUi5czw8gAwQjDF3WexVihdzNyP7tFSaVmLt7sVYDnhgBVnYEUom4ceyub88.png","https://files.peakd.com/file/peakd-hive/rama-dev/23tknNQUVa7EDbcMwwKfMqxEP4iFLbaTZyNvSpL4Mg8ewhY9Wi1NpwAsSamKMdwT75jt3.png"]}"
created2025-06-09 00:59:00
last_update2025-06-09 00:59:00
depth0
children3
last_payout2025-06-16 00:59:00
cashout_time1969-12-31 23:59:59
total_payout_value0.639 HBD
curator_payout_value0.637 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,542
author_reputation2,929,614,633,023
root_title"🎮 Building my first Discord Bot with NodeJS + Mongo DB"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id143,249,950
net_rshares4,190,571,113,988
author_curate_reward""
vote details (23)
@hivebuzz ·
Congratulations @rama-dev! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/https://hivebuzz.me/@rama-dev/comments.png?202506071406"></td><td>You made more than 50 comments.<br>Your next target is to reach 100 comments.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@rama-dev) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out our last posts:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202505-delegations"><img src="https://images.hive.blog/64x128/https://i.imgur.com/fg8QnBc.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202505-delegations">Our Hive Power Delegations to the May PUM Winners</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-1749431577
categoryhive-122422
json_metadata{"image":["https://hivebuzz.me/notify.t6.png"]}
created2025-06-09 01:12:57
last_update2025-06-09 01:12:57
depth1
children0
last_payout2025-06-16 01:12:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length942
author_reputation369,400,114,746,106
root_title"🎮 Building my first Discord Bot with NodeJS + Mongo DB"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id143,250,082
net_rshares0
@web-gnar ·
this is cooool... hive integration!? 
properties (22)
authorweb-gnar
permlinkre-rama-dev-sxpypx
categoryhive-122422
json_metadata{"tags":["hive-122422"],"app":"peakd/2025.6.1","image":[],"users":[]}
created2025-06-12 01:27:33
last_update2025-06-12 01:27:33
depth1
children1
last_payout2025-06-19 01:27:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length37
author_reputation166,060,805,999,971
root_title"🎮 Building my first Discord Bot with NodeJS + Mongo DB"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id143,307,777
net_rshares0
@rama-dev ·
Thanks! Yes is totally posible! The bot works like a backend so you can add s hive account that receives and send tokens
properties (22)
authorrama-dev
permlinkre-web-gnar-sxqlxk
categoryhive-122422
json_metadata{"tags":["hive-122422"],"app":"peakd/2025.6.1","image":[],"users":[]}
created2025-06-12 09:48:57
last_update2025-06-12 09:48:57
depth2
children0
last_payout2025-06-19 09:48:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length120
author_reputation2,929,614,633,023
root_title"🎮 Building my first Discord Bot with NodeJS + Mongo DB"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id143,313,264
net_rshares0