Skip to content

Development Setup

Gamer100309 edited this page Dec 25, 2025 · 1 revision

🔧 Development Setup

Set up a development environment for contributing to the bot.


📋 Prerequisites

Before starting, ensure you have:

  • Node.js 18+ (Download)
  • npm (comes with Node.js)
  • Git (Download)
  • Code Editor (VS Code recommended)
  • GitHub Account
  • Discord Account

🚀 Quick Start

1. Fork the Repository

  1. Go to GitHub Repository
  2. Click "Fork" (top right)
  3. Fork to your account

2. Clone Your Fork

git clone https://github.com/YOUR_USERNAME/MC-Server-Status-Bot.git
cd MC-Server-Status-Bot
cd "Mc Server Stats Bot"

3. Install Dependencies

npm install

4. Create Test Bot

See Discord Bot Setup to create a test bot.

Important: Use a separate test bot, not your production bot!

5. Configure Bot

Create global-config.json:

{
  "token": "YOUR_TEST_BOT_TOKEN_HERE",
  "language": "en"
}

6. Run the Bot

node index.js

Expected output:

[INFO] Bot started successfully
[INFO] Logged in as TestBot#1234
[INFO] Ready to serve 1 guilds

🛠️ Development Tools

Recommended: VS Code

Extensions:

  • ESLint - Code linting
  • Prettier - Code formatting
  • GitLens - Git integration
  • Discord.js Snippets - Code snippets

Optional: Nodemon

Auto-restart on file changes:

# Install globally
npm install -g nodemon

# Run bot with auto-restart
nodemon index.js

🧪 Testing Environment

Create Test Server

  1. Create a Discord server for testing
  2. Invite your test bot
  3. Create test channels:
    • #bot-testing
    • #status-test
    • #debug

Test Minecraft Server

Option 1: Local Server

  • Run Minecraft server locally
  • Test IP: localhost:25565

Option 2: Public Test Server

  • Use public test servers
  • Example: mc.hypixel.net

Option 3: Mock Server

  • Use debug tools to simulate responses

📁 Project Setup

Directory Structure

Your workspace should look like:

MC-Server-Status-Bot/
├── .git/
├── Mc Server Stats Bot/
│   ├── node_modules/
│   ├── classes/
│   ├── configs/
│   ├── texts/
│   ├── Debug/
│   ├── index.js
│   ├── package.json
│   └── global-config.json  ← You create this
└── README.md

Important Files

Don't commit:

  • global-config.json (has your token!)
  • node_modules/ (too large)
  • configs/*.json (test data)
  • .env files

Check .gitignore:

node_modules/
global-config.json
configs/*.json
*.log
.env

🔍 Running Debug Tools

Master Debug Script

Run all diagnostics:

node Debug/master-debug.js

Individual Tools

Validate token:

node Debug/token-validator.js

Test network:

node Debug/network-test.js

Check configs:

node Debug/config-validator.js

Test commands:

node Debug/command-tester.js

Batch Testing

Windows:

Test_all_debug_tools.bat

Linux/Mac:

chmod +x Test_all_debug_tools.sh
./Test_all_debug_tools.sh

🐛 Debugging

Console Logging

Add debug logs:

console.log('[DEBUG] Server status:', status);
console.error('[ERROR] Failed to query:', error);

VS Code Debugger

Create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Bot",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/Mc Server Stats Bot/index.js"
    }
  ]
}

Use breakpoints:

  1. Click left of line number
  2. Press F5 to start debugging
  3. Code pauses at breakpoint

Discord.js Debug Events

Enable debug logging:

client.on('debug', info => {
  console.log('[Discord.js]', info);
});

📝 Code Style

Use Consistent Formatting

Install Prettier:

npm install --save-dev prettier

Create .prettierrc:

{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5"
}

Follow Existing Style

  • 2 spaces indentation
  • Single quotes for strings
  • Semicolons required
  • camelCase for variables
  • PascalCase for classes

🔄 Git Workflow

Daily Workflow

# 1. Start of day - sync with main
git checkout main
git pull upstream main
git push origin main

# 2. Create feature branch
git checkout -b feature/my-feature

# 3. Make changes
# ... edit files ...

# 4. Test changes
node index.js
# Test in Discord

# 5. Commit changes
git add .
git commit -m "feat: add new feature"

# 6. Push to your fork
git push origin feature/my-feature

# 7. Create PR on GitHub

Keeping Fork Updated

Add upstream remote (once):

git remote add upstream https://github.com/Gamer100309/MC-Server-Status-Bot.git

Update your fork:

git checkout main
git pull upstream main
git push origin main

🧪 Testing Checklist

Before submitting code:

Functionality Tests

  • Bot starts without errors
  • All commands work (/setup, /reload, etc.)
  • Server monitoring works
  • Embeds display correctly
  • Buttons/menus function

Edge Cases

  • Server offline handling
  • Invalid IP/port handling
  • Network timeout handling
  • Permission errors handling
  • Invalid config handling

Code Quality

  • No console errors
  • No unused variables
  • Code follows style guide
  • Comments added where needed
  • No debug code left

Documentation

  • README updated if needed
  • Wiki updated if needed
  • Code comments added
  • Changelog updated

🔧 Common Issues

"Cannot find module"

Solution:

npm install

"Invalid token"

Solution:

  1. Check global-config.json
  2. Verify token is correct
  3. No extra spaces

Port already in use

Solution:

# Find and kill process
# Windows:
netstat -ano | findstr :3000
taskkill /PID <PID> /F

# Linux/Mac:
lsof -ti:3000 | xargs kill

Bot offline in Discord

Solutions:

  1. Check token is valid
  2. Check internet connection
  3. Check Discord status
  4. Verify bot is running

📚 Helpful Resources

Documentation

Tools

Community


💡 Development Tips

Use Descriptive Names

// ❌ Bad
const x = await fetch();
const arr = [];

// ✅ Good
const serverStatus = await fetchServerStatus();
const onlineServers = [];

Handle Errors Properly

// ❌ Bad
try {
  doSomething();
} catch (e) {}

// ✅ Good
try {
  doSomething();
} catch (error) {
  logger.error('Failed to do something:', error);
  // Handle error appropriately
}

Comment Complex Code

// ❌ Bad - no comment
if (a && (b || c) && !d) {
  // ...
}

// ✅ Good - explains logic
// Check if user has permission AND
// (is admin OR has setup role) AND
// is not banned
if (hasPermission && (isAdmin || hasSetupRole) && !isBanned) {
  // ...
}

Test Edge Cases

// Test with:
// - Empty strings
// - null/undefined
// - Very large numbers
// - Special characters
// - Network failures

🎯 Next Steps

Now that your environment is set up:

  1. Explore the code - Read through existing files
  2. Find an issue - Check GitHub issues
  3. Make changes - Start small
  4. Test thoroughly - Use all debug tools
  5. Submit PR - Follow contribution guidelines

🔗 Related Pages


← Back to Home

Clone this wiki locally