Connect Discord to your agents for messaging, events, and bot interactions.
Overview
The Discord integration lets your agents send messages, respond to events, and interact with Discord servers through your own bot.
Why "Bring Your Own Key" (BYOK)?
By creating your own Discord application and bot, you get complete control over which servers receive your bot and what events it can respond to.
Benefits:
- Your own bot — customize the name, avatar, and permissions
- Isolated events — only receive events from servers where your bot is invited
- Full control — configure exactly which intents and events to use
- Webhook verification — secure interactions with your public key
Prerequisites
Before connecting, you'll need:
- A Discord account
- A Discord server where you have admin permissions (to invite your bot)
Step 1: Create a Discord Application
- Go to the Discord Developer Portal
- Click New Application
- Name your application (e.g., "Inference Agent")
- Agree to the Terms of Service
- Click Create
Step 2: Create a Bot
- In your application, go to the Bot section
- Click Add Bot
- Customize your bot:
- Username — the name shown in servers
- Icon — your bot's avatar
- Under Privileged Gateway Intents, enable what you need:
| Intent | Allows |
|---|---|
| Presence Intent | See user online/offline status |
| Server Members Intent | See member join/leave events |
| Message Content Intent | Read message text (required for most bots) |
- Copy the Token — you'll need this
Important: Never share your bot token. If compromised, regenerate it immediately.
Step 3: Configure OAuth2
- Go to the OAuth2 section
- Copy the Client ID and Client Secret
- Add a redirect URL:
| Environment | Callback URL |
|---|---|
| Production | https://app.inference.sh/settings/secrets/oauth/discord |
| Staging | https://app.staging.inference.sh/settings/secrets/oauth/discord |
| Local dev | http://localhost:3000/settings/secrets/oauth/discord |
- Under OAuth2 URL Generator, select scopes:
identify— access user infoemail— access user emailguilds— see user's serversbot— add bot to servers
Step 4: Get Your Credentials
From your Discord application, collect:
| Credential | Location | Purpose |
|---|---|---|
| Application ID | General Information | OAuth authentication |
| Client Secret | OAuth2 | OAuth authentication |
| Bot Token | Bot | Send messages, receive events |
| Public Key | General Information | Verify interaction webhooks |
Step 5: Connect in inference.sh
Configure credentials
- Go to Settings → Secrets → Integrations
- Find Discord and click Configure
- Enter your credentials:
- Application ID (Client ID)
- Client Secret
- Bot Token
- Public Key (for webhook verification)
- Click Save credentials
These are stored securely as encrypted secrets.
Authorize the connection
- Click Connect
- You'll be redirected to Discord to authorize
- Select which server to add the bot to
- Review bot permissions
- Click Authorize
- Done! Your Discord integration is now active.
Inviting Your Bot to Servers
To use your bot in a server, it needs to be invited with the right permissions:
- Go to OAuth2 → URL Generator in the Developer Portal
- Select scopes:
bot,applications.commands - Select bot permissions based on your needs:
| Permission | Allows |
|---|---|
| Read Messages/View Channels | See channels and messages |
| Send Messages | Post messages |
| Manage Messages | Delete/pin messages |
| Read Message History | Access older messages |
| Add Reactions | React to messages |
| Use Slash Commands | Respond to /commands |
- Copy the generated URL and open it
- Select a server and authorize
Agent chat and event triggers
Agent messaging channel webhooks (per-agent chat endpoints like Slack's) are not available for Discord yet. Only Slack is registered for POST /agents/{id}/channel/{provider} today. See Slack integration for the supported setup.
Discord event triggers (for example discord.message.created, discord.member.joined) are available after you connect via OAuth. Subscribe to them on an agent in the workspace — no global webhook URL is required.
Do not point Discord's Interactions Endpoint URL at https://api.inference.sh/webhooks/discord — that path is not implemented. Slash commands and button interactions must be hosted on your own infrastructure for now.
Capabilities
| Capability | Description | Required Scopes |
|---|---|---|
discord.identify | Access user info | identify |
discord.email | Access user email | identify, email |
discord.guilds | List user's servers | guilds |
discord.guilds.members.read | Read server members | guilds.members.read |
discord.messages.read | Read messages | messages.read |
discord.bot | Add bot to servers | bot |
Using in apps
Declare Discord requirements in your app:
1integrations:2 - key: discord.bot3 description: Send messages to Discord45 - key: discord.guilds6 description: List available servers7 optional: trueAt runtime, your app receives:
1DISCORD_ACCESS_TOKEN=oauth2-user-token2DISCORD_BOT_TOKEN=bot-token3DISCORD_USER_ID=123456789Example: Send a message
1import discord2import os34client = discord.Client(intents=discord.Intents.default())56@client.event7async def on_ready():8 channel = client.get_channel(CHANNEL_ID)9 await channel.send("Hello from my AI agent! 🤖")10 await client.close()1112client.run(os.environ["DISCORD_BOT_TOKEN"])Example: Using webhooks (simpler)
1import requests2import os34webhook_url = "https://discord.com/api/webhooks/..."56requests.post(webhook_url, json={7 "content": "Hello from my AI agent! 🤖"8})Example: REST API
1import requests2import os34headers = {5 "Authorization": f"Bot {os.environ['DISCORD_BOT_TOKEN']}"6}78# Send a message9response = requests.post(10 f"https://discord.com/api/v10/channels/{channel_id}/messages",11 headers=headers,12 json={"content": "Hello!"}13)Gateway Events (Real-time)
For real-time events, your bot connects to Discord's Gateway:
| Event | Trigger |
|---|---|
MESSAGE_CREATE | New message posted |
MESSAGE_REACTION_ADD | Reaction added |
GUILD_MEMBER_ADD | User joined server |
GUILD_MEMBER_REMOVE | User left server |
INTERACTION_CREATE | Slash command or button click |
Note: Gateway connections require a persistent process. For simpler use cases, consider using webhooks or the REST API.
Security
- Your bot — you control the application and its permissions
- Public key verification — interactions are cryptographically verified
- Bot token — keep this secret; regenerate if compromised
- Permission scopes — bots only get permissions you explicitly grant
Revoking access
- From inference.sh: Settings → Integrations → Disconnect
- From Discord: Server Settings → Integrations → Remove bot
- Regenerate token: Developer Portal → Bot → Reset Token
Troubleshooting
"Invalid token"
- Verify your bot token is correct
- Check if the token was regenerated
- Ensure no extra spaces in the token
"Missing permissions"
- The bot needs specific permissions for each action
- Re-invite the bot with the required permissions
- Check Server Settings → Roles for the bot's role
"Missing access"
- Your bot isn't in the server, or lacks channel access
- Invite the bot or check channel permissions
"Interaction failed"
- Verify your Public Key in inference.sh matches Discord
- Check that the Interactions Endpoint URL is correct
"Message content intent required"
- Enable Message Content Intent in Bot settings
- This is required to read message text
Rate Limits
Discord has rate limits to prevent abuse:
| Action | Limit |
|---|---|
| Messages per channel | 5/5s |
| Global requests | 50/s |
| Gateway connections | 1/5s |
The Discord libraries handle rate limiting automatically.