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_TOKENENV BOT_TOKEN=$BOT_TOKENRUN pip install -r requirements.txtCMD [ "python", "bot.py" ]
3) Add 'Procfile' in the same directory and add this command in it.
'worker: python (script name).py'
'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)'
'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 .'
'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'
'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'
'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
Post a Comment