This article won’t only be talking about Discord bots and it’s not intended to be a proper introduction to them. If you’re looking for that, or even how to create your own bot,

To understand this article fully, you’ll need some understanding of JavaScript, MongoDB, Mongoose ODM, Node.js, Promises and Async/Await, and some general programming knowledge to understand some of the syntax used.

I won’t really touch base on the set up of MongoDB and Mongoose either.

Here are some links if you need to learn a bit more:

To get started, I’m going to talk in-depth about a couple of issues I had with the creation of Jeetbot.

It’s a long read so I put a tl;dr at the end.


So, What’s The Issue?

In my journey to creating a useful Discord bot for discord users and myself, there came a point where I was retrieving data from my MongoDB database too many times. In a happy, land-of-the-free type of internet, all the reads/writes would cost me nothing. But transferring data back and forth on the internet costs money at times, and I wanted to scale this bot properly, so I needed to save some of the data locally, within the bot.

One of the things that the bot has to keep an eye on are user inputs that change the database. This means that users are actively mutating/changing certain options and this is happening asynchronously with the rest of the other Discord servers the bot was on.

That doesn’t sound too hard to fix…

I thought I needed to set up a hash map data structure when the bot initializes and makes changes to the local cache when database changes occur. But it wasn’t that easy. Let me describe below what I had encountered in my process trying this out.

#redux #discord-bot #javascript #discord #programming

Discord Bots and State Management
7.10 GEEK