Step 1: Get the repo ready
- Node (discord.js): commit
package.jsonandpackage-lock.json, and add astartscript. Putnode_modules/in.gitignore. - Python (discord.py): commit
requirements.txt. Putvenv/and__pycache__/in.gitignore. - Java (JDA): commit the Gradle or Maven build files. Check whether your host builds from source or expects a runnable jar; if it expects a jar, build a fat jar in CI or locally.
- Add
.envto.gitignore. Read the token withprocess.env.BOT_TOKENoros.environ["BOT_TOKEN"].
Step 2: Check you never pushed the token
Search your history (git log -p | grep -i token). If a token was ever committed, reset it in the Discord Developer Portal. Deleting the commit isn't enough, because the old value can still be found.
Step 3: Connect the repo to your host
On discordbothost:
- Open your bot's Deploy section and choose the repository and branch.
- Public repos need no token. For a private repo on a paid plan, create a fine-grained personal access token with read-only access to just that repo, and paste it in.
- Save the deploy setup. In GitHub repository settings, add the webhook URL and secret shown in the dashboard. Choose
application/jsonand the push event. A push to that branch fetches the code and restarts the bot. - Set
BOT_TOKENand other secrets under environment variables, not in the repo.
Free supports public repositories and auto-deploy on push. Paid plans also support private repositories.
Step 4: Make deploys safe
- Register slash commands on purpose, not on every boot. Re-registering them on each start wastes Discord API calls. Use a separate script or a
--deploy-commandsflag. - Shut down cleanly. Handle SIGTERM so the bot closes its gateway connection when it restarts.
- Use a branch. Deploy from
mainor aproductionbranch, and keep experiments elsewhere. - Pin versions. Lockfiles stop a deploy from pulling a surprise major version.
Other hosts
If your project began as generated code, use hosting a Discord bot built with ChatGPT or Claude to check that you have a complete project, correct dependencies and a test plan before connecting the repository.
Most general platforms (Railway, Render, Heroku) also deploy from Git, but bill per instance or by usage. FadeHost and bot-hosting.net also list GitHub deploys. See best Discord bot hosting for a side-by-side comparison.
Questions
How do I auto-deploy my Discord bot when I push to GitHub?
Use a host with GitHub push-to-deploy: connect the repo and branch, and each push pulls the code and restarts the bot. On discordbothost, Free and paid plans support public repositories. Paid plans also support private repositories.
Can I deploy from a private repository?
On a paid discordbothost plan, yes: add a read-only fine-grained GitHub token for the repo. Public repos need no token.
Should I commit my bot token to GitHub?
Never. Read it from an environment variable set on the host. If a token is ever pushed, reset it in the Discord Developer Portal immediately.
Sources
Related
Why Does My Discord Bot Keep Going Offline?
7 common reasons a Discord bot goes offline (PC sleep, sleeping free hosts, crashes, memory, bad token, intents, rate limits) and how to fix each.
Updated · 4 min readRender Discord Bot Hosting: Free Limits and Setup
Can Render host a Discord bot? Choose a worker or HTTP service, understand free sleep limits, set build commands and move your bot safely.
Updated · 4 min readHow to Host a Discord Bot for Free (Step by Step)
Host a Discord bot 24/7 for free: create the bot, upload your discord.js, discord.py or JDA code to a free host, set the token, and keep it renewed.
Updated · 3 min read