Overview
The Discord integration provides:- Discord Authentication: Allow users to log in with Discord OAuth2
- Role Synchronization: Automatically assign CAD permissions based on Discord roles
- Discord Webhooks: Send notifications to Discord channels for CAD events
- Discord Bot: Automated webhook management and role verification
Prerequisites
Before setting up Discord integration, you need:- A Discord server where you have administrator permissions
- Access to the Discord Developer Portal
- SnailyCAD instance with administrator access
Creating a Discord Application
Create Application
Navigate to the Discord Developer Portal and click New Application. Give it a name (e.g., “SnailyCAD Bot”).
Get Application Credentials
Go to the OAuth2 section and copy:
- Client ID
- Client Secret
Create Bot
Navigate to the Bot section and click Add Bot. Once created:
- Copy the Bot Token
- Enable the following Privileged Gateway Intents:
- Server Members Intent
- Message Content Intent (optional, for future features)
Configure OAuth2 Redirects
In the OAuth2 section, add redirect URLs:Replace
your-cad-domain.com with your actual domain.Environment Configuration
Add these environment variables to your.env file:
To get your Discord Server ID, enable Developer Mode in Discord settings (User Settings > Advanced > Developer Mode), then right-click your server and select Copy ID.
Discord Authentication Setup
Enable Discord Auth Feature
In SnailyCAD, navigate to Admin > Manage > CAD Settings > Features.Enable the Discord Authentication feature.
Configure User Linking
Users can now link their Discord accounts by:
- Going to Account Settings
- Clicking Link Discord Account
- Authorizing the OAuth2 connection
Discord Role Synchronization
Map Discord roles to SnailyCAD permissions for automatic access control.Map Roles to Permissions
Configure role mappings:
- Admin Roles: Users with these Discord roles get admin permissions
- LEO Roles: Access to law enforcement features
- LEO Supervisor Roles: Supervisor-level LEO permissions
- EMS/FD Roles: Access to emergency medical services
- Dispatch Roles: Access to dispatch interface
- Tow Roles: Access to tow operations
- Taxi Roles: Access to taxi operations
- Courthouse Roles: Access to court/legal features
- Whitelist Role: Users must have this role to access the CAD (if whitelisting enabled)
Configure Permission Sets
For each role type, you can configure specific permissions that will be granted:
- View permissions
- Create/edit permissions
- Delete permissions
- Management permissions
Discord Webhooks
Send automated notifications to Discord channels for various CAD events.Configure Event Webhooks
Select Discord channels for each event type:Dispatch Events
- 911 Calls: New emergency calls created
- Unit Status Changes: When units change their status
- Panic Button: When an officer/deputy presses panic button
- BOLOs: New BOLO (Be On the Lookout) created
- Citizen Records: New arrest reports, tickets, warnings
- Warrants: New warrants issued
- LEO Incidents: Law enforcement incidents created
- EMS/FD Incidents: Medical/fire incidents created
- Vehicle Impounded: When a vehicle is impounded
- Citizen Declared Dead: When a citizen is marked deceased
- Bleeter Posts: Social media posts (if enabled)
- User Whitelist Status: Whitelist status changes
- Department Whitelist Status: Department access changes
Add Custom Messages (Optional)
For each webhook, you can add a custom message that will be sent with the notification. Use
{userId} to mention the linked Discord user.Example: {userId} has created a new 911 call!Multiple Discord Servers
You can configure SnailyCAD to work with multiple Discord servers:- Fetch roles and channels from all configured servers
- Each role/channel will be labeled with its server
- All servers must have the bot invited with proper permissions
Troubleshooting
Bot Not Fetching Roles/Channels
- Verify
DISCORD_BOT_TOKENis correct - Ensure bot has proper permissions in your server
- Check that the bot is online in your Discord server
- Verify
DISCORD_SERVER_IDmatches your server
OAuth2 Authentication Failing
- Verify
DISCORD_CLIENT_IDandDISCORD_CLIENT_SECRET - Check redirect URLs in Discord Developer Portal
- Ensure
NEXT_PUBLIC_PROD_ORIGINis correctly set - Check browser console for CORS errors
Webhooks Not Sending
- Verify channels still exist in Discord
- Check bot has “Manage Webhooks” permission
- Ensure the channel is a text channel (not voice/announcement)
- Look for errors in SnailyCAD logs
Role Sync Not Working
- Verify user has linked their Discord account
- Check that Discord roles are correctly mapped
- Ensure bot has “Manage Roles” permission
- Bot’s role must be higher than roles it’s trying to assign
- User needs to re-login after role changes
Security Considerations
API Endpoints
For developers integrating with Discord features:GET /auth/discord- Initiate Discord OAuth2 flowGET /auth/discord/callback- OAuth2 callback handlerDELETE /auth/discord- Unlink Discord accountGET /admin/manage/cad-settings/discord/roles- Fetch Discord rolesPOST /admin/manage/cad-settings/discord/roles- Update role mappingsGET /admin/manage/cad-settings/discord/webhooks- Fetch Discord channelsPOST /admin/manage/cad-settings/discord/webhooks- Update webhook configuration
Best Practices
- Test in Development: Set up a test Discord server before configuring production
- Document Role Structure: Keep track of which Discord roles map to which CAD permissions
- Monitor Webhooks: Regularly check that webhooks are sending to correct channels
- Role Hierarchy: Ensure bot’s Discord role is positioned correctly in server hierarchy
- Limit Permissions: Only grant the bot permissions it needs
Related Documentation
- Webhooks - Configure raw webhooks for external services
- Permissions - Learn about CAD permission system
- Environment Variables - Complete environment configuration reference