Building a community Discord Bot

Building a community Discord Bot

Besides working on my main game projects, I’ve also been tinkering on a fun Bot for the Discord server. To provide a little bit of gaming but also useful functionality for people interested in Orangepixel, the games, and the youtube videos.  I thought it would be fun to do a little Tech-write-up of the work that went into The Ori to maybe inspire others to tinker with it and try their own version.

The starting place

I had previously created a bot using the service provided by It had some strict limitations as to how many interactions or data could be done in the free tier, and when they changed their pricing model, I figured for my use case (a silly bot on my discord) the payment was just to steep and not something I wanted to keep using.

It took some months for me to find time to start figuring out an alternate way to setting up a bot, but I eventually decided to dig in and learn Node, install DiscordJS and purchase a proper Raspberry Pi 4 to act as the bot’s home-base aka server.

Rebuilding the functionality

I had build up some experience with Javascript over the last few decades, but never used Node! So I had to (re)learn a lot of things and figure every little thing out by googling for examples, tweaking some code, trying other stuff, and eventually getting the Bot online and saying “hi!” to me mentioning it.

From there it was slowly building up the functionality that the previous Autocode version had running. My main interest was setting up the whole XP-point and level-up system:  Discord users gain XP points when other people like (give an emoji to) their messages. This was originally somewhat limited due to Autocode’s limitations on data. But now that those limitations are gone, I figured I could extend all the XP to actually reading ALL the messages and give active users XP for just being active in the server!

I could copy a lot of the original Autocode source’s logic and only needed to change various calls and such. I did have to come up with a way to create a database to track all this XP and such, and I actually ended up using simple JSON files stored on the network drive available to the Raspberry Pi.

The Ori is BACK

So after tinkering with it for a while in a private Discord channel, I figured it was time to bring The Ori back into the server and start doing it’s magic for XP and level-up stuff.  As it was running live I found a bunch of things that needed improving, a bunch of things I had coded wrong (for all the Node/JS codes: async is a must for a lot of this something I wasn’t used to from my normal day job!)

Eventually The Ori became a stable bot and I slowly added more of the old functionality like coming up with Trivia questions, random XP events, and even added some extra little features like “the magic word” which gives an extra 100XP points if someone uses it – the word changes randomly every hour or after someone guessed/used it.

Pushing the skills

As The Ori is mostly a fun side-project for me to tinker with, I started figuring out interesting things I could try to add to it, pushing The Ori into more usefulness for the server and also pushing my own skills of programming a Discord BOT (or Raspberry Pi server).

A couple of simple extra options to add to the bot were notifying people of the latest Youtube video that went live (every Thursday!) and also check for new posts on this website. The website uses RSS so that was fairly straightforward, and Youtube also has a feed where you can grab the latest video. By saving the last Youtube video ID and the RSS link we can easily check if there’s a new/different one, or if we should skip it.  We then check these every day at a specific hour and we got nice automated News updates!

I also figured it would be interesting to give people updates on the development state of my current game projects. Since I track everything in the free Trello service, I started looking into options to fetch information from it.  Trello has a REST API available and I knew of the existence of REST api’s, but I don’t really use them in my day to day (or even year to year) work.

Challenge excepted!

Trello has a great functionality for tracking the changes/activity on a specific Trello board, so once I figured out how to do REST API calls and process them, it was a fairly easy and quick thing to get up and running. I will check all the activity within the last 24 hours, and ignore cards that are duplicated (Creating a card and a few minutes later Updating the card, would show that card twice.. you only need the latest updated version of it) and ignoring a few activities like “archived card” (mostly stuff I added to my TODO but then decided they aren’t needed anymore, so I delete them).

Once that functionality was running I added some more code that allows me to tell The Ori to watch another Trello board and specify in which channel it should show the updates for it. So for all my projects I can now track Trello boards and the result will be posted in the proper channel on the server.

Gamers on a budget!

Since the discord is my main community hot spot for people that are fans of Orangepixel games (or my Youtube channel) I figured it would be a cool little thing to have Steam sales show up on the News channel.

I tried that before with having a schedule/agenda for such things, but to be honest, when I setup discounts on various platforms, I often forget to write down the dates and make a note of it. So there’s discounts planned, but even I have no idea when and completely forget about them.

The best way for The Ori to know these things would be to just check Steam! I searched how sites like SteamDB do it (and they have a very good explanation how they actually do it!) and it mostly comes down to scraping the Steam website… not to repeat myself, but : Challenge Excepted!!

I wrote a couple of scraping functions, the first one scraped a Steam Store page for a specific game.. but I figured that would be a bit of an issue. I have about 14 games live on Steam, if they are all on a discount, I’d have to check each game, every day, and that would amount to 14 news posts on the server. SPAM!

My second scraper was to read the Developer page on Steam, and fetch the games from that list. It shows discounted games and full price and pretty much all the info I need for all my games on a single page!  Took some time and effort to get it working, and then I found out that for some reason, the data I get doesn’t include ALL my games.

Still somewhat confused about this, and I have to investigate further on how or why, because that page is the best solution for scraping all sales for a specific developer. I think it might have to do with some dynamic-loading that page does.

Anyway, I needed another, working, solution. My third and right now active scraper simply checks the Steam search page specifying the developer name. This of course is not the best way, but in the case of Orangepixel it works (unique enough name).

Re-using the tricks I learned from scraper I and II , I had it up and running fairly quickly, the search result page is actually much cleaner in it’s HTML output! So we now have discount/sale functionality running for Steam. It will check Steam twice a week (Wednesday and Saturday) which should cover all sales/discounts at least once.

If there is just a single game on sale it will show that game, if there are more discounts it will show a list of the games and give a link to the Developer page for downloads.

What’s next!?

With all that stuff working I, again, have to go figure out some other cool functionality I can add to it.  The first ones will probably be trying to find Android and Switch sales information. Already looked into it a bit, but those two could be a little more difficult to do.. challenge excepted !

I’m also trying to do as much with my own code as possible, there are many NodeJS solutions out there to handle stuff, but I want to use as little as possible and just write my own code. That’s really what makes me so interested in tinkering with this!

Come check out the Bot or ask questions about it over on the Discord:

Come live chat with the developer and other gamers, get exclusive information on new games, features, discounts and BETA access, join the Discord: