Discord Bots and State Management

Discord Bots and State Management

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,

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Building Simple Covid Tracker Discord Bot with Discord.JS

Do you want to create awesome discord bots with Discord.js and node js? Check out this simple guide to write your own corona tracker discord bot.

Discord Bots 3: Coding a Bot with discord.js

It's finally time to write some code! In this video, I demonstrate the very basics of coding a "hello world"-style bot with discord.js.

What is Redux and how Data Flow within Redux

That’s right! Storage should be the first word that should come into your mind. Before all of you bombard me as to how redux relates to a store let me give you some context. Every time you go on a website, you are probably accustomed to seeing some sort of data displaying on the screen and if the data is not ready, then a loading indicator is going to show up.

Getting Started with Making and Hosting Discord Bots with JavaScript and Python

Discord bots can be very simple or very complex according to the needs of your server. Virtually everything can be automated. Getting Started with Making and Hosting Discord Bots with JavaScript and Python

A Discord Bot to Track COVID-19

In this article, I’ll show you how to: Build the most basic Discord Bot. - Link the Bot to a Discord Server. - Add functionality to track Coronavirus cases for a given country.