The Upstreet Agents SDK is now in public beta 🎉 Get started →
bg-pattern
📚 API ReferencePlugins

Discord

Integrate your Agent with Discord, the popular chatting app.

Import

import { Discord } from 'react-agents';

Setup

We highly recommend reading the Discord Developers documentation for in-depth help, and navigating through Discord's API.

Add Discord integration to your agent by following these steps:

Step 1: Create a Discord bot application

Step 2: Configure bot settings

  • From the sidebar, go to the Bot section to get the Token.
  • Click on Reset Token to get your Token and save it somewhere securely.

Make sure to enable all three options here.

  • Presence Intent
  • Server Members Intent
  • Message Content Intent

Step 3: Add the bot to your server

  • From the sidebar, go to the OAuth2 section
  • At the OAuth2 URL Generator, check the bot option
  • In the Bot Permissions, give the relevant permissions to the bot. To enable the bot to talk in the server and respond to messages, you should check "Send Messages". You can check other permissions based on what you want your bot to do.
  • Scroll down a bit to copy the URL:
  • Paste this URL in a new tab where you will have to:
  1. Select the server you want to add the bot to
  2. Authorize the bot

Usage

Add the following Component to your Agent:

import { Discord } from 'react-agents';
 
// ...
return (
<Agent>
  {/* ... */}
  <Discord
    token="YOUR_BOT_TOKEN" // The bot token from Step 2
    channels={[
      "general", // Text channel names the bot should listen to
      "voice-chat" // Voice channel names the bot should listen to
    ]}
    dms={true} // Enable direct messages with the bot
    userWhitelist={[ // Optional: restrict which users can interact
      "user1#1234",
      "user2#5678"
    ]}
  />
  {/* ... */}
</Agent>
);

When you run the following command to get your Discord Agent up and running:

usdk chat

You can now test it in the connected Discord server! Just mention it in one of the channels you specified, and see it talk.

You can see a more detailed guide for this in our Discord Agent example.

Additional Notes

  • The bot will only respond in the specified channels and to whitelisted users (if configured)
  • Voice channel support requires additional Discord permissions (see above)
  • Channel names are case-sensitive and should match exactly
  • For DMs, users must share a server with the bot
  • The bot token should be kept secure and not committed to version control.
  • You can use .env.txt and the useEnv() hook to load it at runtime.
  • If you need to reset the token for security reasons, you can do so in the Discord Developer Portal
  • The bot requires a stable internet connection to maintain WebSocket connection with Discord
  • Rate limits apply to bot actions - see Discord's developer documentation for details

On this page

Facing an issue? Add a ticket.