DEV Community

Andrew Femia
Andrew Femia

Posted on

Discord Bot with Slash Commands, Node.js, and Typescript deployable to Heroku

Guide

A setup guide can be found in the README of the repo:
Discord-Node-Typescript-Template

Summary

While learning how to create a Discord bot, I decided it would be good practice to save and document a boilerplate for the Discord bot setup I had going. I wanted to use strict imports and typescript, and I figured others may too. I also wanted to utilize Slash commands. I was inspired by another blog that I cannot find, but the blog stopped at local development, and there were a few quirks to getting it to deploy on Heroku.

The main script is wrapped in an instantly called async function to enable top level await, and the template is configured with ENV variables.

To deploy to Heroku, the Procfile (without an extension) must exist in your repository with contents:

worker: npm start
Enter fullscreen mode Exit fullscreen mode

Limitations - Version 1.0

Current implementation can only be used for 1 Discord server per bot as GUILD_ID is taken as an environment variable. I will update the repo when another approach is taken.

Let me know if this is helpful or you have any feeback, thanks!

Top comments (3)

Collapse
 
devoskar profile image
Oskar Pietrucha

As I have no experience in making bots, here's my newbie question:
Can I host the bot server on the localhost on raspberry Pi, which then I connect to my private Discord server and use it as my "helper"? Or do I need to use heroku?

Collapse
 
arfemia profile image
Andrew Femia • Edited

As long as you can get Node version 16.* (16.14.2) running on your Pi, I believe you should be fine. Heroku was the easiest option for me but the template is in no way (other than noted below) specific to Heroku.

The only thing I would note is that a Procfile was needed to run the bot properly as a worker on Heroku, so there may be some raspberry Pi node environment equivalent configuration required. Let me know how it goes!

Collapse
 
owen_mcelearney_b89b34c83 profile image
Owen McElearney • Edited

I love good code! This will be a great thing to have for me and my friends on discord. Keep up the good work @arfemia