How to deploy discord bot on heroku with docker

This guide assumes that you have created your own discord bot, installed docker, and have a heroku app ready to be pushed.


1) Build your dockerfile:

FROM python:latest

WORKDIR /
COPY . .
ARG BOT_TOKEN
ENV BOT_TOKEN=$BOT_TOKEN
RUN pip install -r requirements.txt
CMD [ "python", "bot.py" ]

3) Add 'Procfile' in the same directory and add this command in it.
'worker: python (script name).py'

3) Build your discord bot in docker locally by running this command
'docker build --build-arg (environment-variable-for-token)=(token) -t (image name) (current directory)'

example:
'docker build --build-arg BOT_TOKEN=token -t first_bot .'

4) Run 'heroku scale worker=1'

5) Next, tag the image built to the heroku like so
'docker tag (image id) registry.heroku.com/(your-app-name)/worker'

6) After that, push the image to heroku 
'docker push registry.heroku.com/(your-app-name)/worker'

7) Finally, release the image
 'heroku container:push worker -a (your-app-name)'

Note: If you check the output with'heroku local', it will say something like 'discord module not found', it doesn't matter because the bot is already running. Do 'heroku logs -a (app name)' instead 




Comments

Popular posts from this blog

Support for the experimental syntax 'decorators' isn't currently enabled (5:3):

How to add environment variables into Heroku container

Running CQL scripts in Cassandra