Deploy a Discord bot from GitHub
If your code is on GitHub, you no longer need to upload your files by hand. You paste your repository link in the panel, and every restart pulls the latest version of your bot.
Link your repository
- In the panel, open your bot, then the Startup tab.
- Paste your repository link in GitHub repository (
GIT_REPO), for examplehttps://github.com/you/my-bot. Only https links are accepted. - Private repository: paste a GitHub token in GitHub token (
GIT_TOKEN). Public repository: leave it empty. - For a branch other than the default one, enter it in Git branch (
GIT_BRANCH). - Click Restart. The console shows the deployed version, for example
[Kravn] Updated to a1b2c3d: fix ping command.
Keep your Discord token safe
Never put your bot's token on GitHub. Add .env to your .gitignore, create a .env file on the server in the Files tab, then read it in your code.
DISCORD_TOKEN=your-token
In Node.js, with dotenv:
require('dotenv').config();
client.login(process.env.DISCORD_TOKEN);
In Python, with python-dotenv:
from dotenv import load_dotenv
import os
load_dotenv()
bot.run(os.environ["DISCORD_TOKEN"])
Remember to add dotenv to your package.json, or python-dotenv to your requirements.txt. The .env on the server is kept at every update.
Even simpler: paste your token in Startup > Discord bot token. Your bot receives it as TOKEN, DISCORD_TOKEN and BOT_TOKEN, with no .env file.
Update your bot
- Send your changes to GitHub with
git push. - Click Restart in the panel.
Dependencies are reinstalled only if package.json, package-lock.json or requirements.txt changed. To keep the current version with no update on start, turn off Auto update (AUTO_UPDATE).
Good to know
- Your
.env,node_modules,.venv, your databases and your logs are kept at every update. - If GitHub doesn't respond, your bot starts with the version it already has, and the console says so.
- If you uploaded your bot by hand before, some files in the repository may have the same name. Nothing is replaced: the console tells you which files to delete.
- The GitHub token is visible in the panel to you and to subusers who have access to the Startup tab.
Going further
- Free Discord bot hosting
- Ready-made Discord bots
- Frequently asked questions
- A question? Come to our Discord.