Included here is a basic template for getting a Discord bot up and running in python utilizing the Discord.py library
I have also added in some of the required files to have this bot be hosted on Heroku with a PostgreSQL database backend.
- Fork this repo
- Initialize a virtual python environment
- pip install -r requirements.txt
- Create a new Discord application with a bot user attached.
- Set your discord bots token into the .env file
- Add .env to your .gitignore file
- In the OAuth2 setting, generate a URL with a bot scope and copy that link into your browser
- Select which of the servers you own to add the bot to
- Run the main.py file!
- Create the new application in Heroku either in the dashboard or CLI, and install the Heroku PostgreSQL add-on (The Hobby Dev tier should be sufficient for most needs)
- Go into the application settings, and add your DISCORD_TOKEN as a new Config Var.
- Copy the DATABASE_URL for your new postgres database and past that into your local .env file in order to run the connection locally. (Note that this url does change so you may have to update your local .env value every once in a while.)
- Check that your Procfile points the worker to your main python file containing the bot run token.
- I personally find it easiest to connect my application to the corresponding github repo, and have it automatically deploy with pushes to the repo, but your mileage may very.
- Deploy it!