D&D Beyond Discord Bot

Zachary McKinnon
Fandom Engineering
Published in
5 min readMar 14, 2019

The D&D Beyond team recently launched a Discord server and decided we wanted to create a bot that could integrate with D&D Beyond. Now, simply by typing in the name of a spell, monster, magic item (and so on), you can have that object’s data appear in your Discord server — with a handy link back to the D&D Beyond website! While the bot is in alpha, it can only be used in the official D&D Beyond Discord server, but we’re hoping to roll it out to everyone in the near future.

D&D Beyond Discord Bot !spell command.

Side Project

It’s easy to overwork yourself on a team as busy as D&D Beyond. We obviously have a ton of stuff going on, but we also believe in slack time. Discord integration wasn’t a key feature that we were planning on rolling out, but it was something that our developers wanted to make happen; so we took it on as a side project. Long story short, that means that people who were passionate about it worked on it during slack time and personal time.

It’s sort of like how The Legend of Zelda: Link’s Awakening first started as a relaxing after-hours project for the Zelda team at Nintendo, and then eventually got published as a full game.

Choosing Technology

Choosing what language to code in is sometimes the hardest part of a project. Most of the D&D Beyond source code is written in C#, so we usually lean toward .NET if it makes sense because of the expertise we have on our teams. We’ve also used Docker on ECS for many of our recent projects, and the results have been fantastic. We wanted to build on our recent experiences with both Docker and .NET to create something a little different.

Since this project was a Discord bot and not a web application, we were able to do exactly that: something a little different. Building this tool with Docker actually turned out to be simpler than our normal setup because of the lack of load balancers and public networking.

One element that made it easier to develop this tool was an awesome open source project called Discord.Net. This team had never made a Discord bot together before, and Discord.Net allowed us to get started without having to reinvent the wheel. Using their example code, we had a connected bot going in less than an hour. They also have their own active Discord community, which we quickly joined. Thank goodness for them, and thank you to everyone who answered our questions! You helped us master this tool in no time!

Minimum Viable Product

Even though this was an after-hours side project, we always want our tools to be useful and powerful. We prioritized creating the simplest usable tool possible, and then iterate and expand from there. This Discord bot is already super useful by simply providing on-demand text, straight from the D&D rulebooks — but it could be so much more. Stay tuned; we’re going to be tinkering and iterating with this bot a lot in the near future.

One of the more complex things will be authentication, that is, how to display paid content to users who don’t own that content. We don’t want people using this tool to steal content from the website, but we also want people who have paid for it to be able to use it with this bot. It’s a tricky issue, so please bear with us. In the meantime, though, Wizards of the Coast has graciously allowed us (and everyone else) to provide free “SRD” content on our website. We’ve allowed this tool to use that free content for now, with all paid content off-limits while we tinker around.

While we figure that out, we’re focusing on on adding cool features, and getting feedback from our community.

Feature Flags

We have lots of ideas for this project and we wanted to be able to release as often as possible, so we added feature flags for our commands. Luckily, Discord.Net gives us a way to do this with preconditions. We were able to write a little class that helped:

Now, to only show the command if our flag is on, we just need to add:

[FeatureFlagPrecondition(“conditions”)]

Another interesting note for this project is that it was our first project to use LaunchDarkly for feature flagging. The teams are incredibly excited for this tool. This will allow us to decouple deployments from releases. (We are using this on the Encounter Builder project too. Technically, it is already deployed, we just need to iterate more and then flip the switch!)

Analytics

This project is a little different than our normal web project in regards to analytics. We usually use Google Analytics for our web projects, but because this project is a console application, it wasn’t as easy to just copy and paste a script on a webpage. Instead, we wrote an HttpClient that uploads events to Google Analytics. (Of course, this is wrapped in an abstraction so it can be easily changed in the future.)

Monitoring

We use StatusCake for monitoring, but again, it wasn’t conducive to our normal monitoring practices because it isn’t a web project that can be polled from a third party service. Luckily, StatusCake has a feature called push monitoring that allows us to push a heartbeat every so often to tell our monitoring service we are still up and running.

Release

We are currently in an Alpha release. This means the bot is only available on our server and we have lots of control as to how it is used. Hopefully, people are interested enough in it to play around with it and we can collect enough feedback to delight our customers. We have plenty of nascent ideas for additional commands for this bot to react to, so expect to see some fun stuff in the future. Also, we need to implement sharding to be able to scale the bot up in the future.

No promises, but it would be great if we could share this bot with any Discord server that wanted it. The goal is eventually to make the bot public so that anyone can add the bot to their server. Let’s not worry about that until we’re out of alpha, though!

--

--