Discord Bot Setup
This guide walks through creating and configuring a Discord application for the Forum API.
Create Discord Application
-
Open the Developer Portal
Go to the Discord Developer Portal
-
Create a new application
Click “New Application” in the top right
-
Name your application
Enter a name like “Forum Sync Bot” and click Create
-
Note your Application ID
On the General Information page, copy the Application ID (also called Client ID). You’ll need this for
DISCORD_CLIENT_ID.
Configure the Bot
-
Navigate to Bot settings
Click Bot in the left sidebar
-
Add a bot
Click “Add Bot” if not already created
-
Copy the bot token
Click “Reset Token” and copy it. You’ll need this for
DISCORD_TOKEN. -
Configure bot settings
- Public Bot: Disable if you want to control which servers can add it
- Requires OAuth2 Code Grant: Leave disabled
Enable Privileged Intents
The bot needs specific intents to function properly.
-
Scroll to Privileged Gateway Intents
-
Enable these intents:
Intent Required Purpose Message Content Intent Yes Read message content Server Members Intent Optional Sync member data -
Click Save Changes
Configure OAuth2 (Optional)
If you want users to authenticate via Discord on your site:
-
Navigate to OAuth2 → General
-
Add redirect URLs:
http://localhost:3000/auth/callbackhttps://yourdomain.com/auth/callback -
Copy your Client Secret for
DISCORD_CLIENT_SECRET
Generate Bot Invite Link
-
Navigate to OAuth2 → URL Generator
-
Select scopes:
botapplications.commands
-
Select bot permissions:
- Read Messages/View Channels
- Read Message History
- Add Reactions (optional, for reaction tracking)
-
Copy the generated URL
-
Open the URL in your browser to add the bot to your server
Required Permissions
| Permission | Required | Purpose |
|---|---|---|
| View Channels | Yes | See forum channels |
| Read Message History | Yes | Sync existing messages |
| Read Messages | Yes | Receive new messages |
| Add Reactions | Optional | Track reactions |
Permission Integer: 68608
You can use this directly in invite URLs:
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=68608&scope=bot%20applications.commandsEnvironment Variables
Add these to your .env file:
# RequiredDISCORD_TOKEN=your_bot_token_hereDISCORD_CLIENT_ID=your_application_id_here
# For OAuth (optional)DISCORD_CLIENT_SECRET=your_client_secret_hereServer Configuration
Enable Community Features
Forum channels require Community to be enabled:
-
Go to Server Settings → Community
-
Enable Community Features if not already enabled
-
Follow the setup wizard
Create a Forum Channel
-
Right-click a category → Create Channel
-
Select Forum as the channel type
-
Configure:
- Name: e.g., “help-forum”
- Guidelines: Instructions for posting
- Tags: Categories for threads
-
Click Create Channel
Verify Bot Permissions
Ensure the bot role has access to your forum channels:
-
Right-click the forum channel → Edit Channel
-
Go to Permissions
-
Verify the bot role (or its assigned role) has:
- View Channel ✓
- Read Message History ✓
Initial Sync
When the bot joins a server, it automatically:
- Syncs server metadata (name, icon, description)
- Discovers all forum channels
- Syncs existing threads and messages
Manual Resync
Use the /sync slash command if you have admin permissions:
/syncThis triggers a full resync of all forum content.
Troubleshooting
Bot is online but not syncing
- Verify bot has
View Channelspermission on the forum - Check that Message Content Intent is enabled
- Review console logs for error messages
Missing message content
Message content appears as empty because the intent is missing:
- Go to Developer Portal → Bot → Privileged Intents
- Enable Message Content Intent
- Save and restart the bot
Reactions not tracking
- Ensure
Add Reactionspermission is granted - The bot only tracks reactions on synced messages
OAuth not working
- Verify redirect URL matches exactly (including trailing slash)
- Check
DISCORD_CLIENT_SECRETis set correctly - Ensure the redirect URL is added in OAuth2 settings
”Missing Access” errors
The bot can’t see a channel. Check:
- Channel permissions include the bot role
- Category permissions don’t override channel permissions
- Bot isn’t explicitly denied in channel overrides
Rate Limits
Discord has rate limits that the bot handles automatically. For large servers:
- Initial sync may take several minutes
- Avoid triggering multiple resyncs simultaneously
- Check Discord Status if issues persist
Security Best Practices
- Never commit your bot token to version control
- Regenerate token immediately if exposed
- Use environment variables for all secrets
- Consider a secrets manager in production
- Regularly audit which servers the bot has access to