Inference Logoinference.sh

Discord Integration

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:

  1. A Discord account
  2. A Discord server where you have admin permissions (to invite your bot)

Step 1: Create a Discord Application

  1. Go to the Discord Developer Portal
  2. Click New Application
  3. Name your application (e.g., "Inference Agent")
  4. Agree to the Terms of Service
  5. Click Create

Step 2: Create a Bot

  1. In your application, go to the Bot section
  2. Click Add Bot
  3. Customize your bot:
    • Username — the name shown in servers
    • Icon — your bot's avatar
  4. Under Privileged Gateway Intents, enable what you need:
IntentAllows
Presence IntentSee user online/offline status
Server Members IntentSee member join/leave events
Message Content IntentRead message text (required for most bots)
  1. Copy the Token — you'll need this

Important: Never share your bot token. If compromised, regenerate it immediately.


Step 3: Configure OAuth2

  1. Go to the OAuth2 section
  2. Copy the Client ID and Client Secret
  3. Add a redirect URL:
EnvironmentCallback URL
Productionhttps://app.inference.sh/settings/secrets/oauth/discord
Staginghttps://app.staging.inference.sh/settings/secrets/oauth/discord
Local devhttp://localhost:3000/settings/secrets/oauth/discord
  1. Under OAuth2 URL Generator, select scopes:
    • identify — access user info
    • email — access user email
    • guilds — see user's servers
    • bot — add bot to servers

Step 4: Get Your Credentials

From your Discord application, collect:

CredentialLocationPurpose
Application IDGeneral InformationOAuth authentication
Client SecretOAuth2OAuth authentication
Bot TokenBotSend messages, receive events
Public KeyGeneral InformationVerify interaction webhooks

Step 5: Connect in inference.sh

Configure credentials

  1. Go to Settings → Secrets → Integrations
  2. Find Discord and click Configure
  3. Enter your credentials:
    • Application ID (Client ID)
    • Client Secret
    • Bot Token
    • Public Key (for webhook verification)
  4. Click Save credentials

These are stored securely as encrypted secrets.

Authorize the connection

  1. Click Connect
  2. You'll be redirected to Discord to authorize
  3. Select which server to add the bot to
  4. Review bot permissions
  5. Click Authorize
  6. 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:

  1. Go to OAuth2 → URL Generator in the Developer Portal
  2. Select scopes: bot, applications.commands
  3. Select bot permissions based on your needs:
PermissionAllows
Read Messages/View ChannelsSee channels and messages
Send MessagesPost messages
Manage MessagesDelete/pin messages
Read Message HistoryAccess older messages
Add ReactionsReact to messages
Use Slash CommandsRespond to /commands
  1. Copy the generated URL and open it
  2. Select a server and authorize

Interactions (for triggers)

To receive Discord interactions (slash commands, buttons, etc.):

  1. In your Discord app, go to General Information
  2. Set the Interactions Endpoint URL:
    code
    1https://api.inference.sh/webhooks/discord
  3. Discord will verify the endpoint using your Public Key

Capabilities

CapabilityDescriptionRequired Scopes
discord.identifyAccess user infoidentify
discord.emailAccess user emailidentify, email
discord.guildsList user's serversguilds
discord.guilds.members.readRead server membersguilds.members.read
discord.messages.readRead messagesmessages.read
discord.botAdd bot to serversbot

Using in apps

Declare Discord requirements in your app:

yaml
1requirements:2  integrations:3    - key: discord.bot4      description: Send messages to Discord5 6    - key: discord.guilds7      description: List available servers8      optional: true

At runtime, your app receives:

bash
1DISCORD_ACCESS_TOKEN=oauth2-user-token2DISCORD_BOT_TOKEN=bot-token3DISCORD_USER_ID=123456789

Example: Send a message

python
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)

python
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

python
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:

EventTrigger
MESSAGE_CREATENew message posted
MESSAGE_REACTION_ADDReaction added
GUILD_MEMBER_ADDUser joined server
GUILD_MEMBER_REMOVEUser left server
INTERACTION_CREATESlash 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

  1. From inference.sh: Settings → Integrations → Disconnect
  2. From Discord: Server Settings → Integrations → Remove bot
  3. 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:

ActionLimit
Messages per channel5/5s
Global requests50/s
Gateway connections1/5s

The Discord libraries handle rate limiting automatically.


Next

Back to Integrations Overview

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.