Contributing to betterdiscordjs¶
Thank you for your interest in contributing to betterdiscordjs! We welcome contributions from developers of all skill levels. This guide will help you get started.
๐ Quick Start¶
- Fork the repository
- Clone your fork locally
- Install dependencies:
npm install
- Create a feature branch:
git checkout -b feature/your-feature
- Make your changes
- Test your changes
- Submit a pull request
๐ Table of Contents¶
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Testing
- Submitting Changes
- Style Guidelines
- Project Structure
- Documentation
๐ Code of Conduct¶
This project adheres to a code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to the project maintainers.
Our Standards: - Be respectful and inclusive - Focus on constructive feedback - Help others learn and grow - Maintain a welcoming environment
๐ ๏ธ Getting Started¶
Prerequisites¶
- Node.js 16.9.0 or higher
- npm or yarn package manager
- Git
- A Discord bot token for testing
Development Setup¶
-
Fork and clone the repository:
git clone https://github.com/axrxvm/betterdiscordjs.git cd betterdiscordjs
-
Install dependencies:
npm install
-
Set up environment variables:
cp testbot/.env.example testbot/.env # Edit testbot/.env and add your Discord bot token
-
Test the setup:
npm run test
๐ง Making Changes¶
Branch Naming¶
Use descriptive branch names:
- feature/command-cooldowns
- New features
- fix/memory-leak
- Bug fixes
- docs/api-reference
- Documentation updates
- refactor/plugin-system
- Code refactoring
Commit Messages¶
Follow conventional commit format:
type(scope): description
[optional body]
[optional footer]
Types:
- feat
- New feature
- fix
- Bug fix
- docs
- Documentation changes
- style
- Code style changes
- refactor
- Code refactoring
- test
- Adding or updating tests
- chore
- Maintenance tasks
Examples:
feat(commands): add cooldown system
fix(ctx): resolve memory leak in context object
docs(readme): update installation instructions
๐งช Testing¶
Running Tests¶
# Run all tests
npm test
# Run specific test file
npm test -- --grep "Bot class"
# Run tests with coverage
npm run test:coverage
Test Bot¶
Use the test bot to verify your changes:
cd testbot
node index.js
Writing Tests¶
- Write tests for new features
- Update existing tests when modifying functionality
- Ensure tests are descriptive and cover edge cases
- Use the existing test structure as a guide
๐ค Submitting Changes¶
Pull Request Process¶
- Update documentation if needed
- Add tests for new functionality
- Ensure all tests pass
- Update CHANGELOG.md if applicable
- Create a pull request with a clear title and description
Pull Request Template¶
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Refactoring
## Testing
- [ ] Tests pass locally
- [ ] New tests added (if applicable)
- [ ] Manual testing completed
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes (or clearly documented)
๐จ Style Guidelines¶
JavaScript Style¶
- Use ES6+ features where appropriate
- Follow camelCase for variables and functions
- Use PascalCase for classes
- Use UPPER_SNAKE_CASE for constants
- Prefer async/await over promises
- Use destructuring when beneficial
Code Formatting¶
// Good
const { Client, GatewayIntentBits } = require('discord.js');
class Bot {
constructor(token, options = {}) {
this.token = token;
this.options = options;
}
async start() {
// Implementation
}
}
// Avoid
var client = require('discord.js').Client;
Documentation¶
- Use JSDoc for function documentation
- Include parameter types and return types
- Provide examples for complex functions
- Keep comments concise and relevant
/**
* Creates a new command with the specified options.
* @param {string} name - The command name
* @param {Function} handler - The command handler function
* @param {object} [options={}] - Additional command options
* @param {string} [options.description] - Command description
* @param {boolean} [options.slash] - Enable slash command
* @returns {object} The created command object
* @example
* bot.command('ping', async (ctx) => {
* await ctx.reply('Pong!');
* }, { description: 'Check bot latency' });
*/
command(name, handler, options = {}) {
// Implementation
}
๐๏ธ Project Structure¶
Understanding the project structure helps you know where to make changes:
betterdiscordjs/
โโโ Bot.js # Main bot class
โโโ index.js # Framework entry point
โโโ loaders/ # Command and event loaders
โ โโโ commands.js
โ โโโ events.js
โโโ plugins/ # Plugin system
โ โโโ BasePlugin.js
โ โโโ PluginManager.js
โ โโโ built-in/ # Built-in plugins
โโโ utils/ # Utility modules
โ โโโ cache.js
โ โโโ ctx.js # Context object
โ โโโ logger.js
โ โโโ ...
โโโ testbot/ # Example implementation
โโโ docs/ # Documentation
โโโ tests/ # Test files
Where to Make Changes¶
- Core functionality โ
Bot.js
,utils/
- Plugin system โ
plugins/
- Command/Event loading โ
loaders/
- Documentation โ
docs/
- Examples โ
testbot/
,docs/examples/
๐ Documentation¶
Updating Documentation¶
- Update relevant
.md
files indocs/
- Include code examples
- Update API references
- Test documentation examples
Documentation Structure¶
docs/
โโโ README.md # Main documentation index
โโโ getting-started/ # Beginner guides
โโโ api/ # API reference
โโโ plugins/ # Plugin documentation
โโโ examples/ # Code examples
โโโ deployment/ # Deployment guides
๐ Reporting Issues¶
Bug Reports¶
Include: - Clear description of the issue - Steps to reproduce - Expected vs actual behavior - Environment details (Node.js version, OS, etc.) - Code samples if applicable
Feature Requests¶
Include: - Clear description of the feature - Use case and motivation - Proposed implementation (if you have ideas) - Examples of similar features
๐ท๏ธ Release Process¶
Releases follow semantic versioning (SemVer): - MAJOR - Breaking changes - MINOR - New features (backward compatible) - PATCH - Bug fixes (backward compatible)
๐ค Community¶
- Be respectful and constructive
- Help others learn and contribute
- Share knowledge and best practices
- Celebrate contributions from all skill levels
๐ Getting Help¶
- Documentation - Check the docs first
- Issues - Search existing issues
- Discussions - Ask questions in GitHub Discussions
- Discord - Join our community server (if available)
๐ Recognition¶
Contributors are recognized in: - CHANGELOG.md - For significant contributions - README.md - In the acknowledgments section - Release notes - For major features
Thank you for contributing to betterdiscordjs! Your efforts help make Discord bot development better for everyone. ๐