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
Interactions (for triggers)
To receive Discord interactions (slash commands, buttons, etc.):
- In your Discord app, go to General Information
- Set the Interactions Endpoint URL:
code
1https://api.inference.sh/webhooks/discord - Discord will verify the endpoint using your Public Key
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:
1requirements:2 integrations:3 - key: discord.bot4 description: Send messages to Discord5 6 - key: discord.guilds7 description: List available servers8 optional: trueAt runtime, your app receives:
1DISCORD_ACCESS_TOKEN=oauth2-user-token2DISCORD_BOT_TOKEN=bot-token3DISCORD_USER_ID=123456789Example: Send a message
1import discord2import os3 4client = discord.Client(intents=discord.Intents.default())5 6@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()11 12client.run(os.environ["DISCORD_BOT_TOKEN"])Example: Using webhooks (simpler)
1import requests2import os3 4webhook_url = "https://discord.com/api/webhooks/..."5 6requests.post(webhook_url, json={7 "content": "Hello from my AI agent! 🤖"8})Example: REST API
1import requests2import os3 4headers = {5 "Authorization": f"Bot {os.environ['DISCORD_BOT_TOKEN']}"6}7 8# 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.