Creating a Discord bot with Node.js and Electron

Recently I created a basic Discord bot for the school’s computing club group using the Discord.js library for Node.js.

At the moment it has basic functionality such as replying to mentions with random messages, making “I’m dad” jokes and welcoming new members.

After I created the bot I thought it would be interesting to try and add a GUI to let me turn parts of it on and off. I’d never used Electron before so I thought I’d try it out.

I used Comic Sans (of course) and ended up with the following HTML and CSS interface:

I was pleasantly surprised by how easy it was to create the Electron interface. I obviously haven’t done a brilliant job of designing it, but the process of adding it to the Node.js app was simple. I’m looking forward to using Electron again in future projects.

At the moment the code is a bit of a mess because I added the Electron GUI after everything else. The code for the bot itself is located in the main process instead of the renderer process, so I have to use IPC messages for the GUI to communicate with the bot. In the future I might refactor it so that the bot runs in the renderer process instead.

While writing it I made the mistake of including the node_modules folder in the Git repository. It turns out that the Electron executable is more than 100MB, which is bigger than the maximum file size allowed on GitHub. I found a solution on Stack Overflow to remove the node_modules folder from my commits before I pushed them to GitHub, which solved the problem.

Leave a comment

Design a site like this with WordPress.com
Get started