Discord Bot Setup

Complete guide to setting up your Discord bot for Ticket System

Bot Setup Overview

This guide covers everything you need to know about configuring your Discord bot for Ticket System, including:

  • Creating and configuring the bot application
  • Setting up proper permissions
  • Configuring OAuth2 for authentication
  • Testing bot functionality
  • Troubleshooting common issues

Create Discord Application

1. Access Developer Portal

  1. Go to the Discord Developer Portal
  2. Click "New Application"
  3. Enter a name for your application (e.g., "Ticket System Bot")
  4. Click "Create"

2. Configure Application Settings

General Information

  • Name: Ticket System Bot
  • Description: Professional ticket management system
  • Icon: Upload your bot icon (512x512 recommended)

Bot Configuration

  • Username: TicketSystem
  • Public Bot: No (for private use)
  • Requires OAuth2 Code Grant: Yes

Configure Bot Settings

1. Bot Permissions

Navigate to the "Bot" section and configure the following permissions:

Permission Required Description
Send Messages Send ticket responses and notifications
Manage Threads Create and manage ticket threads
Use Slash Commands Register and use slash commands
Attach Files Send transcripts and attachments
Embed Links Send rich embeds with links
Read Message History Access message history for transcripts
Add Reactions Add reactions to messages
Use External Emojis Use custom emojis in responses
Manage Messages Edit and delete messages when needed

2. Generate Bot Token

  1. In the Bot section, click "Reset Token"
  2. Copy the generated token
  3. Store it securely (you'll need it for configuration)
  4. Never share this token publicly

Security Warning: Keep your bot token secure. If compromised, reset it immediately and update your configuration.

OAuth2 Configuration

1. Configure OAuth2 Settings

  1. Navigate to "OAuth2" → "General"
  2. Copy the Client ID and Client Secret
  3. Add your redirect URI: https://yourdomain.com/api/auth/callback/discord

2. Configure Scopes

Set the following scopes for OAuth2:

  • identify - Access user information
  • guilds - Access server information
  • guilds.join - Join servers (if needed)

3. Generate OAuth2 URL

Use this URL format for OAuth2:

https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=8&scope=bot%20applications.commands&redirect_uri=https%3A%2F%2Fyourdomain.com%2Fapi%2Fauth%2Fcallback%2Fdiscord&response_type=code

Invite Bot to Server

1. Generate Invite Link

  1. Go to "OAuth2" → "URL Generator"
  2. Select the following scopes:
    • bot
    • applications.commands
  3. Select the required permissions (as listed above)
  4. Copy the generated URL

2. Add Bot to Server

  1. Open the generated invite URL
  2. Select your Discord server
  3. Ensure all permissions are checked
  4. Click "Authorize"
  5. Verify the bot appears in your server

3. Verify Bot Permissions

  • Check that the bot has the correct role permissions
  • Verify the bot can see the channels it needs to access
  • Test that the bot can send messages

Configure Webhook Integration

1. Webhook URL

Set up the webhook URL for communication between the web panel and bot:

# In your environment configuration
BOT_WEBHOOK_URL=http://localhost:3001
BOT_WEBHOOK_PORT=3001

2. Webhook Security

  • Generate a secure webhook secret
  • Configure webhook signature verification
  • Set up rate limiting for webhook endpoints
  • Monitor webhook delivery status

3. Test Webhook Connection

# Test webhook connectivity
curl -X POST http://localhost:3001/webhook/test \
  -H "Content-Type: application/json" \
  -H "X-Webhook-Signature: your-signature" \
  -d '{"test": true}'

Slash Commands Setup

1. Register Commands

Ticket System uses the following slash commands:

  • /ticket - Create a new ticket
  • /close - Close the current ticket
  • /transcript - Generate ticket transcript
  • /add - Add user to ticket
  • /remove - Remove user from ticket

2. Command Permissions

Command Who Can Use Description
/ticket Anyone Create a new support ticket
/close Staff Close the current ticket
/transcript Staff Generate ticket transcript
/add Staff Add user to ticket
/remove Staff Remove user from ticket

Testing Bot Functionality

1. Basic Connectivity Test

# Check if bot is online
# The bot should appear online in your Discord server

# Test bot response
# Send a message in a channel the bot can see

2. Permission Test

  • Test creating a ticket thread
  • Verify the bot can send messages in the thread
  • Test slash command functionality
  • Verify webhook communication

3. Integration Test

  1. Create a ticket through the web panel
  2. Verify the bot creates the thread
  3. Send messages in the thread
  4. Test closing the ticket
  5. Verify transcript generation

Troubleshooting

Common Issues

Bot Not Responding

  • Check if bot is online
  • Verify token is correct
  • Check bot permissions
  • Review application logs

Permission Errors

  • Verify bot role permissions
  • Check channel permissions
  • Ensure bot has required scopes
  • Re-invite bot with correct permissions

Webhook Failures

  • Check webhook URL configuration
  • Verify network connectivity
  • Check webhook signature
  • Review webhook logs

OAuth2 Issues

  • Verify redirect URI matches exactly
  • Check client ID and secret
  • Ensure scopes are correct
  • Clear browser cache and cookies

Debug Commands

# Check bot status
curl -X GET http://localhost:3001/health

# Check webhook status
curl -X GET http://localhost:3001/webhook/status

# View bot logs
pm2 logs discord-ticket-bot

# Test OAuth2 flow
curl -X GET https://yourdomain.com/api/auth/signin

Security Best Practices

1. Token Security

  • Store tokens in environment variables
  • Never commit tokens to version control
  • Rotate tokens regularly
  • Use different tokens for development and production

2. Permission Principle

  • Grant minimum required permissions
  • Regularly audit bot permissions
  • Remove unused permissions
  • Monitor bot activity

3. Network Security

  • Use HTTPS for all webhook communications
  • Implement webhook signature verification
  • Set up rate limiting
  • Monitor for suspicious activity

Next Steps

After setting up your Discord bot:

  1. Configure Permissions - Set up role-based access
  2. Create Categories - Set up ticket categories
  3. Configure Auto-Close - Set up automatic ticket management
  4. Set Up Dashboard - Configure the web interface