Overview
Bounty’s Discord integration provides:- User Account Linking: Connect Discord accounts to Bounty profiles
- Bot Installation: Add the Bounty bot to your Discord server
- Webhook Notifications: Send bounty updates to Discord channels
- Guild Management: Track which servers have the bot installed
Prerequisites
- Discord account with server management permissions
- Discord Application with OAuth2 and Bot configured
Discord Application Setup
Create Discord Application
Go to the Discord Developer Portal and click New Application.Give your application a name (e.g., “Bounty Bot”).
Configure OAuth2
In your application settings, navigate to OAuth2 → General.Add redirect URLs:
- Development:
http://localhost:3000/api/auth/callback/discord - Production:
https://your-domain.com/api/auth/callback/discord
Configure Bot
Navigate to the Bot section in your application.Click Add Bot if you haven’t already.Configure bot settings:
- Public Bot: Enable if you want others to add your bot
- Requires OAuth2 Code Grant: Disable
- Privileged Gateway Intents: Enable as needed
Set Bot Permissions
The Bounty bot requires the following permissions:
- Send Messages - Post notifications
- Embed Links - Rich embeds for bounty updates
- Read Message History - Context for commands
2147485696Setting Up Webhooks
Discord webhooks allow Bounty to send notifications to specific channels.Navigate to Server Settings
In your Discord server, go to Server Settings → Integrations → Webhooks.
Create New Webhook
Click New Webhook and configure:
- Name: Bounty Notifications
- Channel: Select the channel for bounty updates
- Avatar: Upload a logo (optional)
You can create multiple webhooks for different notification types (e.g., one for general updates, one for high-value bounties).
User Account Linking
Users can link their Discord accounts to their Bounty profiles.Linking Process
Authorize Application
Users grant permission to:
- Identify their Discord account
- Access basic profile information
Viewing Linked Account
API endpoint:discord.getLinkedAccount
Unlinking Account
API endpoint:discord.unlinkAccount
Bot Installation
Add the Bounty bot to your Discord server to enable notifications and commands.Getting the Bot Install URL
API endpoint:discord.getBotInstallUrl
- Client ID from
DISCORD_CLIENT_ID - Required permissions (
2147485696) - OAuth scopes:
botandapplications.commands
Manual Installation
To manually construct the bot install URL:YOUR_CLIENT_ID with your Discord application’s client ID.
Guild Management
Track which Discord servers (guilds) have the Bounty bot installed.Viewing Connected Guilds
API endpoint:discord.getGuilds
How It Works
- Fetches user’s Discord guilds from Discord API using their OAuth token
-
Queries the database for guilds where:
- Bot is installed (
removedAtis null) - User is a member (guild ID matches)
- Guild belongs to the active organization
- Bot is installed (
- Returns the intersection of bot-installed servers and user’s servers
Webhook Notifications
Bounty sends Discord webhook notifications for key events.Bounty Created/Funded
When a bounty is funded, a notification is sent:BOUNTY_FEED_WEBHOOK_URL or DISCORD_WEBHOOK_URL.
Implementation
Webhooks are sent from the Stripe webhook handler after successful payment:Webhook failures are logged but don’t affect payment processing. They’re fire-and-forget to prevent payment delays.
Permissions Reference
The bot requires specific Discord permissions:| Permission | Value | Purpose |
|---|---|---|
| Send Messages | 2048 | Post notifications |
| Embed Links | 16384 | Rich embeds |
| Read Message History | 65536 | Context for commands |
| Total | 2147485696 | Combined permissions integer |
Troubleshooting
Bot Install URL Not Working
Cause:DISCORD_CLIENT_ID not configured.
Solution: Ensure DISCORD_CLIENT_ID is set in your environment variables.
User Guilds Not Loading
Cause: Discord OAuth token expired or user hasn’t linked Discord. Solution:- Check if user has linked Discord account
- If linked, token may have expired - ask user to reconnect
- Verify
guildsscope is included in OAuth flow
Webhook Not Sending
Checklist:- Verify
DISCORD_WEBHOOK_URLorBOUNTY_FEED_WEBHOOK_URLis set - Check webhook URL is valid and channel exists
- Ensure webhook wasn’t deleted in Discord server settings
- Review server logs for webhook errors
”Failed to fetch user guilds”
Causes:- Access token expired
- User revoked access
- Discord API downtime
- Ask user to reconnect Discord account
- Check Discord API status: https://discordstatus.com
- Verify OAuth scopes include
guilds
API Reference
getBotInstallUrl
Generates the Discord bot installation URL.
Returns: { url: string | null, configured: boolean }
getLinkedAccount
Retrieve the user’s linked Discord account.
Returns: { linked: boolean, account: DiscordAccount | null }
unlinkAccount
Remove the Discord account connection.
Returns: { success: boolean }
getGuilds
Get Discord servers where the bot is installed and the user is a member.
Scoped to: Active organization
Returns: { guilds: Guild[], userGuildIds: string[] }
Security Considerations
- OAuth tokens are stored encrypted in the database
- Webhook URLs should be treated as secrets
- Bot tokens (if used) must never be committed to version control
- Use HTTPS for all webhook endpoints in production