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
- Go to the Discord Developer Portal
- Click "New Application"
- Enter a name for your application (e.g., "Ticket System Bot")
- 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:
2. Generate Bot Token
- In the Bot section, click "Reset Token"
- Copy the generated token
- Store it securely (you'll need it for configuration)
- 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
- Navigate to "OAuth2" → "General"
- Copy the Client ID and Client Secret
- 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
- Go to "OAuth2" → "URL Generator"
- Select the following scopes:
- bot
- applications.commands
- Select the required permissions (as listed above)
- Copy the generated URL
2. Add Bot to Server
- Open the generated invite URL
- Select your Discord server
- Ensure all permissions are checked
- Click "Authorize"
- 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
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
- Create a ticket through the web panel
- Verify the bot creates the thread
- Send messages in the thread
- Test closing the ticket
- 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:
- Configure Permissions - Set up role-based access
- Create Categories - Set up ticket categories
- Configure Auto-Close - Set up automatic ticket management
- Set Up Dashboard - Configure the web interface