How to Open Source Discord Bots
In this article
Open-sourcing a Discord bot means publishing its source code publicly (usually on GitHub) so others can view, contribute, or self-host it. This helps you build a community, get code reviews, and share useful tools. Before you start, you'll need a Discord bot that already works, a GitHub account, and a basic understanding of Git and your bot's code structure.
What You'll Need
- A Discord bot that you have written or have permission to share.
- A GitHub (or similar) account.
- Git installed on your computer (or use GitHub's web upload).
- Basic knowledge of your bot's code and dependencies.
Step-by-Step
- Prepare your code for public release. Remove any hardcoded tokens, API keys, or database credentials. Use environment variables or a config file that is not committed (like a .env file). Create a
.gitignorefile to exclude sensitive files, node_modules, logs, and build artifacts. - Choose a license. Decide how others can use your code. Common choices: MIT (permissive), Apache 2.0 (with patent protection), GPL (copyleft). If you don't add a license, others cannot legally use your code. Create a
LICENSEfile with the full license text. - Write a README. This is the first thing people see. Include: what the bot does, features, prerequisites (Node.js version, etc.), setup instructions (install dependencies, configure env), commands list, and a link to invite the bot to a server. Keep it clear and concise.
- Add a contribution guide (optional but recommended). Create a
CONTRIBUTING.mdfile explaining how to report issues, submit pull requests, and code style guidelines. This makes it easier for others to help. - Create a repository on GitHub. Go to GitHub, click the '+' icon, select 'New repository'. Name it (e.g., my-discord-bot), set it to Public, and optionally add a README, .gitignore, and license (you can also add them later).
- Initialize Git in your project folder. Open a terminal in your bot's directory and run
git init. - Add and commit your files. Run
git add .to stage all files (make sure your .gitignore is correct), thengit commit -m "Initial commit". - Link your local repo to GitHub. Copy the remote URL from your GitHub repo page (HTTPS or SSH). Run
git remote add origin https://github.com/yourusername/repository-name.git. - Push your code. Run
git push -u origin main(or master if that's your default branch). If you created a README on GitHub, you may need to pull first:git pull origin main --allow-unrelated-histories. - Verify the repository. Go to your GitHub page and confirm all files are there. Check that no sensitive files are visible.
- Add a hosting or self-hosting guide. In your README, explain how to run the bot locally and, if applicable, on a cloud service (like Heroku, Railway, or a VPS). Include commands like
npm installandnode index.js. - Announce and maintain. Share your repo on Discord communities, Reddit, or Twitter. Respond to issues and pull requests to keep the project alive.
Common Mistakes
- Committing your bot token. This is the #1 mistake. Even if you delete it later, it's compromised. Always use environment variables.
- Forgetting a license. Without it, your code is technically all-rights-reserved, and others can't legally use it.
- Including large files or build artifacts that bloat the repo.
- Not testing the setup instructions. Make sure a fresh clone works.
- Using a private repository by mistake when you intended public.
Tips
- Use a
.env.examplefile to show what environment variables are needed without revealing actual values. - Add a badge to your README showing build status or license (e.g., from shields.io).
- Keep your code modular and well-commented to help contributors.
- Set up issue templates (bug report, feature request) to streamline feedback.
- If you use a framework like discord.js, specify the version in your package.json.
- Consider adding a
SECURITY.mdfile to tell people how to report vulnerabilities privately.
Troubleshooting
If your push fails: Check that you've added the correct remote URL and that you have permission. If the repo already has files, pull first or use git push --force only if you're sure.
If you accidentally committed a token: Revoke it immediately in the Discord Developer Portal, generate a new one, and update your .env. Then, remove the token from git history using tools like git filter-branch or BFG Repo-Cleaner, and force-push. Also consider changing any other secrets that were exposed.
If the bot doesn't run after cloning: Check that you've installed all dependencies (npm install or pip install -r requirements.txt), set up the .env file correctly, and that your Node.js/Python version matches the requirements.
If GitHub shows a huge diff or missing files: Verify your .gitignore is correct and that you didn't accidentally exclude important files. You can use git status to see what's tracked.
Frequently Asked Questions
Can I open-source a bot that uses someone else's code?
Only if you have permission (e.g., the original license allows it) and you comply with that license's terms (like attribution or sharing alike).
Do I need to include the bot's invite link in the README?
It's helpful, but not required. Many users want to try the bot before deploying it themselves.
What if my bot has a database? How do I share that?
You share the code, not the data. Document the database schema and provide migration scripts if needed. Users will run their own database instance.
Can I still charge for hosting if the code is open source?
Yes. Open source means the code is public, but you can still offer hosted services for a fee. Many companies do this.
How do I handle pull requests?
Review them, test the changes, and merge if they look good. Use GitHub's review tools to comment and request changes.
Should I open-source a bot that I'm making money from?
It depends on your business model. If you rely on exclusivity, maybe not. But open-sourcing can build trust and community, which often outweighs the risk.