Skip to main content
Heroku discontinued free dynos in November 2022. You’ll need a paid Eco Dyno ($5/month) or higher. Additionally, this bot uses discord.js v12 which is outdated.

Overview

Heroku is a cloud platform that supports Node.js applications with git-based deployments. Yato includes a Procfile for Heroku compatibility.

Prerequisites

  • Heroku account (sign up)
  • Heroku CLI installed (download)
  • Git installed
  • Discord bot token
  • MongoDB connection string (use MongoDB Atlas free tier)

Deployment steps

1

Install Heroku CLI

Download and install the Heroku CLI, then login:
heroku login
2

Clone the repository

Clone the Yato bot repository:
git clone https://github.com/qonTesq/Yato.git
cd Yato
3

Create Heroku application

Create a new Heroku app with a unique name:
heroku create yato-bot-yourname
Or let Heroku generate a random name:
heroku create
4

Configure environment variables

Set your environment variables using Heroku config vars:
heroku config:set TOKEN=your_discord_bot_token
heroku config:set MONGO_URI=your_mongodb_connection_string
You can also set config vars through the Heroku Dashboard under Settings > Config Vars.
5

Deploy to Heroku

Push your code to Heroku:
git push heroku main
If your default branch is master:
git push heroku master
6

Scale the worker dyno

The bot uses a worker dyno (defined in Procfile). Scale it to 1:
heroku ps:scale worker=1
7

Verify deployment

Check the bot logs to ensure it’s running:
heroku logs --tail
You should see:
➤ Logged in as YourBotName#1234 (123456789)
✔ Connected to MongoDB

Understanding the Procfile

The included Procfile defines how Heroku runs the bot:
Procfile
worker: node .
  • worker: Dyno type (background worker, not web server)
  • node .: Runs node src/index.js based on package.json main field
Worker dynos don’t require a port binding like web dynos, making them ideal for Discord bots.

Managing your Heroku deployment

View logs

heroku logs --tail

Restart the bot

heroku restart

Update environment variables

heroku config:set VARIABLE_NAME=value
View all config vars:
heroku config

Check dyno status

heroku ps

Setting up MongoDB Atlas

Since Heroku doesn’t provide free database hosting:
1

Create MongoDB Atlas account

Sign up at MongoDB Atlas
2

Create a free cluster

Create a free M0 cluster (512MB storage, shared CPU)
3

Configure network access

In Network Access, add 0.0.0.0/0 to allow connections from anywhere (Heroku IPs are dynamic)
This allows connections from any IP. Secure your database with a strong password.
4

Create database user

In Database Access, create a user with read/write permissions
5

Get connection string

Click “Connect” > “Connect your application” and copy the connection string:
mongodb+srv://username:[email protected]/yato?retryWrites=true&w=majority
Replace <password> with your database user password.

Updating your bot

When you make changes to the code:
1

Commit changes

git add .
git commit -m "Update bot features"
2

Push to Heroku

git push heroku main
Heroku automatically rebuilds and restarts your bot.
3

Monitor deployment

heroku logs --tail

Troubleshooting

Bot is not coming online

1

Check worker dyno

Ensure the worker dyno is running:
heroku ps
If not, scale it:
heroku ps:scale worker=1
2

Verify environment variables

heroku config
Ensure TOKEN and MONGO_URI are set correctly.
3

Check logs for errors

heroku logs --tail

MongoDB connection fails

  • Verify connection string format
  • Ensure Network Access allows 0.0.0.0/0
  • Check database user credentials
  • Test connection locally first

Commands not registering

  • Slash commands may take up to 1 hour to register globally
  • Use GUILD_ID environment variable for instant registration in a test server
  • Check bot permissions in Discord Developer Portal

Dyno exceeds memory quota

Canvas operations can be memory-intensive:
  • Upgrade to Eco Dyno or higher ($5+/month)
  • Optimize Canvas usage in welcome cards
  • Clear caches more frequently

Cost optimization

Heroku Eco Dynos ($5/month) don’t sleep and include 1000 dyno hours, sufficient for one always-on bot.
PlanCostDyno HoursBest For
Eco Dyno$5/month1000 hoursSingle bot, small servers
Basic Dyno$7/monthAlways-onProduction use
Standard Dynos$25+/monthAlways-on + performanceHigh-traffic bots

Alternative deployment

If Heroku doesn’t meet your needs:
  • Docker deployment for any VPS
  • Railway (similar to Heroku with free tier)
  • DigitalOcean App Platform

Additional resources

Build docs developers (and LLMs) love