How to Deploy a Discord Bot from GitHub

How-toBy discordbothostPublished Updated 3 min read

The short answer: Keep the project in GitHub without its token, connect a repository and branch to your host, then set the token privately. A signed push hook can restart the bot with new code. On discordbothost, Free and paid plans include public GitHub deployment. Private repositories need a paid plan and a read-only repository token. Test a small commit before relying on deployment.

Step 1: Get the repo ready

  • Node (discord.js): commit package.json and package-lock.json, and add a start script. Put node_modules/ in .gitignore.
  • Python (discord.py): commit requirements.txt. Put venv/ 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 .env to .gitignore. Read the token with process.env.BOT_TOKEN or os.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:

  1. Open your bot's Deploy section and choose the repository and branch.
  2. 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.
  3. Save the deploy setup. In GitHub repository settings, add the webhook URL and secret shown in the dashboard. Choose application/json and the push event. A push to that branch fetches the code and restarts the bot.
  4. Set BOT_TOKEN and 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-commands flag.
  • Shut down cleanly. Handle SIGTERM so the bot closes its gateway connection when it restarts.
  • Use a branch. Deploy from main or a production branch, 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.

  1. 1https://discordbothost.com/pricing/

Related