Build A Bot (DiscordJS) — A Bot Factory and Revealing Module Design Pattern


As I said, we will transform our previous code into a factory function. This means that we will rely more on parameters and configuration given when using the factory rather than when setting it up. So, first of all, let’s clean up a bit. We’re going to throw out a lot of our old code.


As we will get our config handed in from now on, we need to make a few minor adjustments. First of all, we need to rewrite our bot.load() function as follows.


You might have noticed that our new console log for multiple bots does not tell us which loading message belongs to which bot. To amend this, I’ve made another minor adjustment to add a short tag to those messages.

Wrapping up

We’ve turned our bot code into a bot factory and used well-proven and time-tested design patterns along the way.

Some words about me:

If you want to see more of my work and progress, feel free to follow me and check out my other articles. If you clap feverishly for the articles you like most, it will be easier for me to decide which directions to pursue in following articles so use your ability to cast a vote for future content.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Konrad Abe

Konrad Abe


I’m a Web / App Developer & father 👨‍👩‍👧 doing freelance and part-time agency work since 2003, 💻 building stuff on the side 🕹 and attending conferences 🎟