How to stop my discord bot on herokuapp.com - python

I have my Discord bot deployed to heroku. I can stop it by turning off this thing (the full page). How can I do the same thing through the command line (win10)?

You can use the following command which makes use of Heroku CLI assuming that you have it configured for your app.
heroku ps:scale worker=0

Related

Discord Bot Offline

I coded my bot using nextcord and tried running it 24/7 using Heroku. However, there are no error codes when I deploy my bot, it stays offline. I've used heroku before for my discord-py bots, they all work. This is the first time I am adding slash commands (that work when I run it on my pc) to my bots. I have all the files I need such as requirements.txt, Procfile, runtime.txt and index.py, stored in the same git repo. How do I fix this?
requirement.txt:
nextcord==2.0.0
runtime.txt:
python-3.10.6
procfile:
worker: python3 index.py
I have the worker dyno enabled

Dyno is not enabled

am trying to build a telegram bot on heroku. The bot works fine on my local testing, when I published it to heroku for some reason the dyno is not working. I checked if there any problem in my program bot nothing.
even tried to launch it manually to see if there is any missing package or errors:
heroku run bash -a app1
python bot.py
and the application started normally without any problem.
also tried to restart dynos but nothing happened the dyno is still OFF.
Procfile
worker: python bot.py
PS:
am using the free plan
tried to see the logs but it didn't show any error
2021-10-20T14:59:56.732258+00:00 app[api]: Deploy 348270fc by user *#gmail.com
2021-10-20T14:59:56.732258+00:00 app[api]: Release v9 created by user *#gmail.com
2021-10-20T15:00:08.000000+00:00 app[api]: Build succeeded**
I found the answer after reading heroku documentation on Dynos, because this is a worker dyno not a web dyno you need to rescale it to 1.
PS> heroku scale worker=1
Scaling dynos... done, now running worker at 1:Free
Everything should work fine from there.
Reference:
Dynos and the Dyno Manager
Dyno Types

Heroku: How to auto start Python app on deploy?

I've got a Heroku app which automatically deploys when I'm pushing changes to GitHub. It's a Discord Bot (written in python).
Now I want to automatically start this python script when I'm going to deploy (It should run 24/7 until it's stopped by a new deploy).
I read about Dynos but don't know how to use them. I already added the Procfile with bot: python bot.py but this won't auto start the app. The Dyno is only shown in the resources tab on the dashboard. Using heroku ps -a myapp it responds with No dynos on ⬢ myapp. The bot: python bot.py Dyno in the dashboard also can't be started through that switch.
Screenshot: The switch can't be activated
So I tried to use release: python bot.py which starts the bot but after another deploy the processes are stacking up and the bot is running multiple times.
Don't use a release command for this.
release commands run once as part of the deploy, then they're done. Your application should probably be set up as a web process (if it's supposed to respond to HTTP requests):
web: python myapp.py
or a worker process (if it isn't):
worker: python myapp.py

Error deploying my python telegram bot on heroku

I'm making a Telegram bot on python and today i deployed it on Heroku. The bot had been deployed successfully but i'm having some troubles: first of all, i get an error when being redirected to my app's web page. After that i decided to check my app's logs, and i found this error:
telepot.exception.TelegramError: ('Conflict: terminated by other long poll or webhook', 409, {'ok': False, 'error_code': 409, 'description': 'Conflict: terminated by other long poll or webhook'})
I tried to see if the telegram bot was running, and it is, but instead of answering once to a command, it answer twice. The problem is not with the code, since when i run it locally from my ide, everything is alright.
I tried to find the problem, and i thought that it was another python script running on heroku, so i turned it off, but the problem was still there. I even thought that the script was running locally, but even with my laptop turned off, i get two answers.

Heroku Scheduler With Python Script

How do I run a python script that is in my main directory with Heroku scheduler?
Normally I run this through the command line with Heroku run python "script.py", but this syntax is clearly not correct for the Heroku Scheduler. Where it says "rake do_something" what should the correct syntax be to run a python script here? I've tried "python script.py" and this does not work either.
Thanks!
The Heroku Scheduler will try to run any command you give it. For Python, if you added a mytask.py to
your app repo, you could have the Scheduler run:
python mytask.py
Instead of waiting for the Scheduler to run to see if the command works as expected, you can also test run it like this:
heroku run python mytask.py # or heroku run:detached ...
heroku logs --tail
Another way to use the Scheduler would be to extend your app with a cli tool or a script runner that shares the app context. A popular one for Flask is Flask-Script.
Note: the "rake" references in the Heroku Scheduler docs example is for running tasks with ruby.

Categories