0

Before you start throwing words of advice, here are the things i read on stackoverflow that I already have done :

  1. make a file of type .file (procfile or something) and put worker : python3.8.3 bot.py
  2. make a runtime.txt and put python-3.8.3
  3. make a requirements.txt and put
async-timeout==3.0.1
discord.py==1.3.3

( I didnt make a venv so the modules i thought would be useful i only included those , its just a basic bot , code below)

  1. I am not using any .env files so i didnt have to configure the environment variable settings in Heroku

Lastly here is my bot that works when hosted locally but doesnt work ( not even get online even though build is succesful )

import discord
streak1=0
client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello! You are '+str(message.author) +' and I am '+str(client.user))

    if "$t1" in message.content:
        global streak1
        streak1+=1
        await message.channel.send('Current Streak is'+str(streak1))


client.run('Normally i put my token here but well..')

successfully built and deployed

Here is a picture of the recent Activity on my Heroku account ( with auto deploy enabled)

----------Edit 1 ----------

I deleted the file of type .file and isntead made an actual Procfile with no extensions and added worker : python3.8.3 bot.py and now the (successful) build log is :





-----> Python app detected

-----> No change in requirements detected, installing from cache

-----> Installing SQLite3

-----> Installing requirements with pip

-----> Discovering process types

       Procfile declares types -> worker

-----> Compressing...

       Done: 48.7M

-----> Launching...

       Released v8

       https://housekeeper0.herokuapp.com/ deployed to Heroku


----------Edit 2----------

Heroku logs after i turned maintenance mode off

2020-06-05T15:09:12.771374+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=housekeeper0.herokuapp.com request_id=192d5f69-baa2-45aa-87c2-e825b9b0a3e9 fwd="42.110.144.123" dyno= connect= service= status=503 bytes= protocol=https
2020-06-05T15:09:13.138611+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=housekeeper0.herokuapp.com request_id=2f9e9311-3a52-45c1-bd6d-e97029265ae7 fwd="42.110.128.196" dyno= connect= service= status=503 bytes= protocol=https
2020-06-05T15:09:51.000000+00:00 app[api]: Build started by user valusoutrik@gmail.com
2020-06-05T15:10:14.642049+00:00 app[api]: Release v9 created by user valusoutrik@gmail.com
2020-06-05T15:10:14.642049+00:00 app[api]: Deploy 44992c2a by user valusoutrik@gmail.com
2020-06-05T15:10:14.870453+00:00 heroku[worker.1]: State changed from crashed to starting
2020-06-05T15:10:19.063466+00:00 heroku[worker.1]: Starting process with command `: python3.8.3 bot.py`
2020-06-05T15:10:19.773065+00:00 heroku[worker.1]: State changed from starting to up
2020-06-05T15:10:22.236921+00:00 heroku[worker.1]: Process exited with status 0
2020-06-05T15:10:22.285159+00:00 heroku[worker.1]: State changed from up to crashed
2020-06-05T15:10:23.000000+00:00 app[api]: Build succeeded
2020-06-05T15:10:25.240729+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=housekeeper0.herokuapp.com request_id=08dfc489-44ce-4343-a086-6ca25655333a fwd="42.110.144.123" dyno= connect= service= status=503 bytes= protocol=https
2020-06-05T15:15:00.686869+00:00 heroku[worker.1]: State changed from crashed to starting
2020-06-05T15:15:04.221869+00:00 heroku[worker.1]: Starting process with command `: python3.8.3 bot.py`
2020-06-05T15:15:04.940175+00:00 heroku[worker.1]: State changed from starting to up
2020-06-05T15:15:07.084995+00:00 heroku[worker.1]: Process exited with status 0
2020-06-05T15:15:07.134788+00:00 heroku[worker.1]: State changed from up to crashed

---------Edit 3------------- On using heroku local I get

[OKAY] Loaded ENV .env File as KEY=VALUE Format
8:53:00 AM worker.1 |    File "bot.py", line 7
8:53:00 AM worker.1 |      async def on_ready():
8:53:00 AM worker.1 |          ^
8:53:00 AM worker.1 |  SyntaxError: invalid syntax
[DONE] Killing all processes with signal  SIGINT
8:53:00 AM worker.1 Exited with exit code null

this works perfectly well on my computer without importing async but just having it installed , so i added it to my requirements

My current requirements.txt

git+https://github.com/Rapptz/discord.py
async-timeout==3.0.1
asyncio==3.4.3

i also imported asyncio into my bot.py

  • *"a file of type `.file` (pocfile or something)"* - this isn't confidence-inspiring. [`Procfile`](https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile)? Have you looked at any of the actual *logs* from Heroku, either build (linked in the screenshot) or run? – jonrsharpe Jun 05 '20 at 14:15
  • Actually I read on one question here that you have to EITHER give a procfile and runtime.txt OR requirements.txt , first I tried with requirements.txt and it didnt work so i just made the *procfile* and put it in .( I only know that you shouldnt put `web :` but `worker` ). I did check the the website but what am i supposed to do ? – soutrik das Jun 05 '20 at 14:25
  • what is the result when you open your app? and show us the log file. You can log using `heroku logs --tail --remote [your remote name]` – Darkknight Jun 05 '20 at 14:41

3 Answers3

0

What you should change :

  • In your Profile file :
worker: python bot.py
  • In your requirements.txt :
git+https://github.com/Rapptz/discord.py
MrSpaar
  • 3,979
  • 2
  • 10
  • 25
  • I tried it but still doesnt work , maybe check the last edit i made on the post , i got some useful info on using `heroku local` – soutrik das Jun 06 '20 at 03:24
0

I don't think you should be using Heroku Local.

If you take a look at your logs in your second edit, you aren't running any web processes Error Img. As it is written, the Heroku router is making a GET request to the "/" route, but there is nothing there to send back a response which then causes the app to crash. A simple fix is to add Flask. Create a wsgi.py file and add:

from flask import Flask, Response

app = Flask(__name__)

@app.route('/', methods='GET')
def index():
    status_code = Response(status=200)
    return status_code

if __name__ == "__main__":
    app.run(debug=True)

After that, install Green Unicorn (a production server): pip install gunicorn and: pip freeze > requirements.txt to add Gunicorn to requirements.txt.

Then, in your Procfile above your worker process, add web: gunicorn wsgi:app This handles a GET request by sending back a Status Code response of 200.

Otherwise, you can try scaling the web process down to 0. Open up the terminal and navigate to your directory. When there, login with the Heroku cli command heroku login. Once logged in, run the command heroku ps:scale web=0. More on that here.

  • When i try to scale down to 0 ( OR 1 ( i tried that earlier)) It says `Scaling dynos... ! ▸ Couldn't find that process type (web).` . I am goinf to try the wsgi.py now – soutrik das Jun 06 '20 at 07:07
  • Tried using that wsgi but not getting any logs ( also the bot isnt coming online) – soutrik das Jun 06 '20 at 07:13
0

From this question H14 error in heroku - "no web processes running" i was trying to scale the web dyno but then it hit me i should instead scale up the worker dyno

instead of

heroku ps:scale web=1 --app [my app name]

I did this

heroku ps:scale worker=1 --app [my app name]

and it worked like a charm !