Ok so WTF is this:
Let's say you've made a discord bot on visual studio code but want it on 100% of the time. Heroku provides a free server (kind of like replit.com but you get to use any IDE)!
Instructions:
- Create a requirements.txt for your repository and add
git+https://github.com/nextcord/nextcord
(whatever github library you're using) - Create a Procfile.txt for your repo and add
Worker: python main.py
(make sure filename = main.py) - Log on to Heroku and create a new app
- Go to Settings --> Add Buildpack --> Add Python (Or whatever language you are using)
- Go to Deploy --> Connect with Github --> Choose the branch that you put your main.py code in
- Deploy the branch --> Go to Resources --> Edit & turn on Worker python main.py (refresh if needed)
- Give Heroku around a minute and see your results
Note: You have the option to use a config var (think of a .env file) to hide your API keys
- Go to Settings --> Config Vars --> Create a {key} to call and the api key {value}
- In your main.py file add
import os
andtoken = os.getenv('your_key')
. Call this variable wherever needed - Make sure to redeploy your branch so that heroku runs the updated code
Documentation & Other Method (Harder one in my opinion):
- https://devcenter.heroku.com/articles/how-heroku-works
- https://www.youtube.com/watch?v=BPvg9bndP1U&t=406s
Important Notice
Please note that as of 2023, Discord has required a rule pertaining to discord bots called "gateway intents." For more information on gateway intents, see https://www.pythondiscord.com/pages/tags/intents/