blog.sensay.io

How to Integrate Your Custom Bot with Discord: A Step-by-Step Guide – The Home of your Digital Replica

Written by SensayC | Oct 15, 2024 4:00:00 AM

This comprehensive guide will walk you through the process of integrating your custom bot with Discord, enabling you to interact with it within your Discord server. Follow each step carefully to ensure a smooth setup.

Prerequisites

  • A Pro or Enterprise plan with your bot service (e.g., Sensay AI).
  • A Discord account with permissions to create and manage applications.
  • Access to the Discord Developer Portal.

Step 1: Access Your Bot’s Integration Page

  1. Log in to Your Bot Service: Sign in to your personal dashboard on sensay.io/me
  2. Navigate to Integrations:
    • Locate and click on the Discord Icon.
    • This will take you to the Integration Page where you can manage various integrations.

Step 2: Create a New Application in Discord

  1. Visit the Discord Developer Portal:
  2. Create a New Application:
    • Click on the “New Application” button.
    • Name Your Application: Enter a name for your bot (this will be the bot’s username on Discord).
    • Click “Create” to proceed.

Step 3: Set Up Your Bot

  1. Navigate to the Bot Settings:
    • In your new application’s dashboard, select the “Bot” tab from the left-hand menu.
  2. Add a Bot to Your Application:
    • Click on “Add Bot”.
    • Confirm by clicking “Yes, do it!” when prompted.
  3. Customize Your Bot:
    • Username: You can change the bot’s username here if desired.
    • Icon: Upload an image to serve as your bot’s avatar.
  4. Save Changes:
    • Click “Save Changes” after customizing.

Obtain Your Bot’s Token

  1. Reset the Bot Token:
    • In the “Bot” section, click on “Reset Token”.
    • Confirm the action when prompted.
  2. Copy the Token:
    • Click “Copy” to copy your bot’s token.
    • Important: Keep this token secure. Do not share it publicly.

Configure Bot Permissions and Intents

  1. Set Bot Permissions:
    • Scroll down to the “Privileged Gateway Intents” section.
    • Toggle on the necessary intents your bot requires (e.g., “Presence Intent”, “Server Members Intent”, “Message Content Intent”).
  2. Make Your Bot Public:
    • Ensure the “Public Bot” option is enabled if you want others to invite your bot.
  3. Save Changes:
    • Click “Save Changes” to apply your settings.

Step 4: Invite Your Bot to Your Discord Server

  1. Generate an OAuth2 URL:
    • Navigate to “OAuth2” > “URL Generator” in the Developer Portal.
    • Under “Scopes”, select “bot”.
    • Under “Bot Permissions”, select the permissions your bot needs (e.g., “Send Messages”, “Read Message History”, “Administrator”).
  2. Copy the Generated URL:
    • The URL at the bottom is your custom invite link.
  3. Invite the Bot:
    • Paste the invite link into your browser.
    • Select the server you want to add the bot to.
    • Click “Authorize” and complete any CAPTCHA if prompted.

Step 5: Connect Your Bot to Your Bot Service

  1. Return to Your Bot Service Integration Page:
    • Go back to the integration page where you left off.
  2. Paste the Bot Token:
    • Find the field labeled “Bot Token” or “Discord Token”.
    • Paste the token you copied earlier.
  3. Connect the Bot:
    • Click on the “Connect” or “Authorize” button.
    • The service will now authenticate and connect to your bot.

Step 6: Interact with Your Bot in Discord

  1. Open Discord:
    • Launch the Discord application or open it in your browser.
  2. Navigate to Your Server:
    • Go to the server where you invited the bot.
  3. Check Bot’s Presence:
    • The bot should appear in the member list. ( it’ll only appear after it has been connected with Sensay system)
  4. Identify Available Channels:
    • The bot will have access to channels based on the permissions you set.
    • It should be able to interact in text channels in your server.
  5. Start a Conversation:
    • In a text channel, type a message to the bot. For example:


      @YourBotName Hello! How are you today?
  6. Alternatively, you can direct message the bot.

Await Bot’s Response:

  • The bot should reply based on its programmed capabilities. The bot replies based on the last 25 messages of the channels as a context, or on the whole private history (if via DM). Moreover, of course it will leverage the replica’s training and knowledge it’s connected to.

Additional Tips

  • Managing Channels:
    • You can control which channels the bot has access to by adjusting channel permissions in Discord.
  • Bot Commands:
    • Familiarize yourself with any specific commands or functionalities your bot offers.
  • Security:
    • Never share your bot’s token. If you suspect it has been compromised, reset it immediately from the Developer Portal. You should disconnect it from the integration page as well then reconnect with new token.
  • Support:
    • Refer to your bot service’s detailed guide or support resources for additional help.

Conclusion

By following these steps, you’ve successfully integrated your custom bot with Discord. You can now interact with your bot within your server, enhancing your Discord community’s experience

Frequently Asked Questions

Q1: What are Privileged Gateway Intents, and why do I need them?

  • A: Privileged Gateway Intents are options that allow your bot to receive certain sensitive events from Discord, such as member information and message content. Enabling them is essential for your bot to function correctly, especially if it needs to track member statuses or read messages.

Q2: How do I customize my bot’s responses?

  • A: Bot responses are typically managed through your bot service’s platform (Sensay). Log in to Sensay dashboard to update responses. More you train your Replica, better the response will be.

Q3: Can I invite my bot to multiple servers?

  • A: Yes, if your bot is set to be public. Share the generated OAuth2 URL with others, and they can invite the bot to their servers.

Resources