C
CoderspaE
/Documentation

Discord Integration

Connect your Discord server with CoderspaE to create an interactive coding community with real-time notifications, bot commands, and battle updates.

Overview

The Discord integration enables seamless connection between your Discord server and CoderspaE platform, bringing coding battles and competitions directly to your community.

Key Features

  • • Real-time battle notifications and updates
  • • Interactive Discord bot with coding commands
  • • Automated tournament announcements
  • • Leaderboard and statistics in Discord channels
  • • Direct challenge creation from Discord
  • • Code execution and testing via bot commands

Bot Setup

Step 1: Invite CoderspaE Bot

Invite the official CoderspaE Discord bot to your server:

1. Click the invite link: https://discord.com/oauth2/authorize?client_id=CODERSPAE_BOT_ID&scope=bot&permissions=8
2. Select your Discord server
3. Grant necessary permissions:
   - Send Messages
   - Read Message History
   - Embed Links
   - Use Slash Commands
   - Manage Messages
   - Add Reactions

Step 2: Configure Bot Permissions

Set up proper role hierarchy and channel permissions:

# Recommended channel setup
📋 General Channels:
  #coding-announcements (CoderspaE bot can post)
  #battle-notifications (Automated updates)
  #leaderboard (Real-time rankings)

🎮 Battle Channels:
  #active-battles (Live battle updates)
  #battle-history (Past battle results)
  #tournaments (Tournament info)

🔧 Configuration:
  #bot-config (Admin commands only)
  #bot-logs (Error and debug logs)

Step 3: Link Server to CoderspaE

# Use this command in your Discord server
/coderspae setup

# Follow the interactive setup:
1. Provide your CoderspaE API key
2. Select notification channels
3. Configure battle preferences
4. Set tournament settings
5. Choose leaderboard display options

Bot Commands

General Commands

/coderspae profile [user]

Display user profile and statistics

/coderspae profile @username
/coderspae profile             # Shows your own profile

/coderspae leaderboard [type] [limit]

Show server or global leaderboard

/coderspae leaderboard global 10
/coderspae leaderboard server 20
/coderspae leaderboard weekly 5

/coderspae stats [period]

Display coding statistics and achievements

/coderspae stats daily
/coderspae stats weekly
/coderspae stats monthly
/coderspae stats alltime

Battle Commands

/battle create [problem] [mode] [duration]

Create a new coding battle

/battle create two-sum quick 30m
/battle create binary-search ranked 1h
/battle create custom-problem fun 45m

/battle join [battle_id]

Join an existing battle

/battle join 12345
/battle join                   # Shows available battles

/battle challenge @user [problem]

Challenge another user to a 1v1 battle

/battle challenge @alice two-sum
/battle challenge @bob random    # Random problem selection

Code Execution Commands

/code run [language] [code]

Execute code directly in Discord

/code run python
```python
def hello():
    return "Hello World!"
print(hello())
```

/code test [problem_id] [language] [code]

Test code against problem test cases

/code test two-sum javascript
```javascript
function twoSum(nums, target) {
    // Your solution here
}
```

Webhooks Configuration

Setting Up Webhooks

Configure webhooks to receive real-time notifications in your Discord channels:

# Create webhook in Discord channel
1. Go to Channel Settings > Integrations > Webhooks
2. Click "New Webhook"
3. Copy the webhook URL
4. Add to CoderspaE dashboard under Discord settings

Webhook Events

EventDescriptionChannel
battle.startedNew battle begins#battle-notifications
battle.completedBattle ends with results#battle-history
tournament.announcedNew tournament available#tournaments
leaderboard.updatedWeekly/monthly rankings updated#leaderboard
achievement.unlockedUser earns new achievement#announcements

Webhook Payload Example

{
  "event": "battle.completed",
  "timestamp": "2024-01-15T14:30:00Z",
  "battle": {
    "id": "battle_12345",
    "problem": "Two Sum",
    "mode": "ranked",
    "duration": "30 minutes",
    "participants": 15
  },
  "results": {
    "winner": {
      "username": "codingmaster",
      "time": "8m 32s",
      "language": "python"
    },
    "top_3": [
      {"username": "codingmaster", "time": "8m 32s", "points": 100},
      {"username": "algoexpert", "time": "9m 15s", "points": 85},
      {"username": "pythondev", "time": "10m 01s", "points": 70}
    ]
  },
  "embed": {
    "title": "🏆 Battle Completed: Two Sum",
    "color": 0x00FF00,
    "fields": [
      {"name": "Winner", "value": "codingmaster (8m 32s)", "inline": true},
      {"name": "Participants", "value": "15 coders", "inline": true},
      {"name": "Next Battle", "value": "Binary Search in 30 mins", "inline": false}
    ]
  }
}

Custom Embeds & Formatting

Battle Notification Embed

# Battle Started Embed
{
  "embeds": [{
    "title": "⚔️ New Battle Started!",
    "description": "Join the coding battle now!",
    "color": 0x3498db,
    "fields": [
      {
        "name": "Problem",
        "value": "Two Sum",
        "inline": true
      },
      {
        "name": "Difficulty",
        "value": "Easy",
        "inline": true
      },
      {
        "name": "Duration",
        "value": "30 minutes",
        "inline": true
      },
      {
        "name": "Mode",
        "value": "Ranked Competition",
        "inline": true
      },
      {
        "name": "Participants",
        "value": "3/20 joined",
        "inline": true
      },
      {
        "name": "Prize Pool",
        "value": "500 XP + Badges",
        "inline": true
      }
    ],
    "footer": {
      "text": "Use /battle join to participate!"
    },
    "timestamp": "2024-01-15T14:30:00Z"
  }]
}

Leaderboard Embed

# Weekly Leaderboard Embed
{
  "embeds": [{
    "title": "📊 Weekly Leaderboard",
    "description": "Top performers this week",
    "color": 0xf39c12,
    "fields": [
      {
        "name": "🥇 1st Place",
        "value": "**codingmaster** - 2,450 XP\n15 battles won",
        "inline": false
      },
      {
        "name": "🥈 2nd Place", 
        "value": "**algoexpert** - 2,180 XP\n12 battles won",
        "inline": false
      },
      {
        "name": "🥉 3rd Place",
        "value": "**pythondev** - 1,950 XP\n10 battles won", 
        "inline": false
      }
    ],
    "thumbnail": {
      "url": "https://coderspae.com/assets/trophy.png"
    },
    "footer": {
      "text": "Resets every Monday at 00:00 UTC"
    }
  }]
}

Role Management

Automatic Role Assignment

Configure automatic role assignment based on CoderspaE achievements:

# Configure role mappings
/coderspae config roles

# Example mappings:
Beginner Coder     → 0-100 XP
Intermediate Coder → 101-500 XP  
Advanced Coder     → 501-1000 XP
Expert Coder       → 1001-2500 XP
Master Coder       → 2500+ XP

Battle Winner      → Won any battle
Tournament Victor  → Won tournament
Speed Demon        → Solved in < 5 minutes
Algorithm Master   → 100+ problems solved

Language-Specific Roles

# Assign roles based on preferred languages
Python Programmer   → 50+ Python solutions
JavaScript Ninja    → 50+ JavaScript solutions  
Java Developer      → 50+ Java solutions
C++ Expert         → 50+ C++ solutions
Go Enthusiast      → 25+ Go solutions
Rust Warrior       → 25+ Rust solutions

Polyglot           → Solutions in 5+ languages

Advanced Features

Scheduled Tournaments

Automatically announce and manage scheduled tournaments:

/coderspae schedule tournament
  - Name: Weekly Algorithm Challenge
  - Time: Every Saturday 2:00 PM UTC
  - Duration: 2 hours
  - Problems: 3 medium difficulty
  - Channel: #tournaments

Study Groups

Create study groups and practice sessions:

/study create
  - Topic: Dynamic Programming
  - Time: Today 7:00 PM
  - Problems: Fibonacci, Coin Change, LCS
  - Voice Channel: Study Room 1

Code Review Bot

Get automated code review and suggestions:

/review
```python
def two_sum(nums, target):
    for i in range(len(nums)):
        for j in range(i+1, len(nums)):
            if nums[i] + nums[j] == target:
                return [i, j]
```

# Bot response:
❌ Time Complexity: O(n²) - Can be optimized
💡 Suggestion: Use hash map for O(n) solution
✅ Code Style: Good variable naming
⚠️  Edge Cases: Consider empty array handling

Daily Challenges

Automated daily coding challenges with streaks:

# Daily challenge posted at 9:00 AM UTC
🌅 Daily Challenge #127

Problem: Valid Parentheses
Difficulty: Easy
Time Limit: 1 hour
Streak Reward: +50 XP

React with ✅ to participate!
Current streak leaders:
🔥 codingmaster: 45 days
🔥 algoexpert: 23 days
🔥 pythondev: 18 days

Troubleshooting

Common Issues

Bot Not Responding

Check bot permissions and ensure it has "Use Slash Commands" enabled.

Webhooks Not Working

Verify webhook URL is correctly configured in CoderspaE dashboard.

Roles Not Assigned

Ensure bot role is higher than assigned roles in server hierarchy.

Rate Limits

Discord API rate limits apply. Large servers may experience delays in notifications during peak activity.