Stammer.ai Docs
  • Welcome
    • 👋Welcome to Stammer.ai
    • 📑About Stammer.ai
    • 🆕New/ Latest Updates
  • START HERE
    • ❓What is Stammer.ai?
    • 🫡Agency Quick Start Guide
    • 📚Glossary
    • 🤑Our Community
  • AI Features
    • 🤖AI Agents (Chatbots)
      • How AI Agents Work
      • How to Build an AI Agent
    • 🔃AI Agent Dashboard
      • (White Label) Marketplace
      • Default Chatbot
      • Share Chatbot
      • Clone Chatbot
      • Chatbot UUID
      • Delete Chatbot
      • Summary (Analytics)
    • 💬Conversations
      • Review Past Conversations
      • Conversation Links
      • Training Better Responses
      • Live Chat
        • Human Handoff Automation (for Live Chat)
    • 📚Knowledge Base Explained
      • 💽Data Storage (Characters)
        • Storage (Characters) Example
      • Copy & Paste Text
      • Upload Documents
      • Scrape Websites
        • 24-hour Auto-Scraping
        • Scraping a Google Doc
        • Google Docs
      • Question & Answer Pairs
      • Data & Content Security
      • Citations/ Sources
      • HTML Rendering (Embed Images & Videos)
    • ✍️Prompting
      • What is a Base System Prompt?
      • Writing a Base System Prompt
      • Prompt Examples (Marketplace)
        • Base System Prompt Template (General)
    • 🔧AI Agent Settings
    • 🎨AI Chat Widget
      • Customize Chat Widget Apperance
      • Chat Widget Pop-Up
      • Initial Messages Pop-Up
      • Chat Widget Voice
    • ⚙️Advanced Settings for AI Agent
      • Model Version
      • Prioritize Question/Answer Results
      • Chatbot Visibility
      • Temperature
      • Message Template
      • Support Email
      • Domains
      • Show Data Sources in Chat Widget
      • Debug Mode
    • Leads 2.0
    • 📈Leads (Legacy)
      • Overview of Lead Generation
      • Lead Collection Form Fields
      • Lead Collection Webhook URL
      • Lead Collection Email Notification
      • In Chat Lead Collection Base System Prompt
      • Sending Lead Data to Zapier
      • Sending Lead Data to GHL
      • Sending Lead Data to Zoho CRM
    • 📅Scheduling
      • AI Scheduling - Simplified
      • AI Scheduling - Experimental (Beta)
        • What is Scheduling?
        • Calendar Integration
          • Google Calendar
        • Appointment Scheduling Activation
        • Appointment Scheduling Webhook URL
        • Appointment Scheduling Email Notification
        • Appointment Scheduling Base System Prompt
        • The Appointment Scheduling Functions & Customizing the Appointment Scheduling Prompt
    • 🧊Integrations
      • Embed Chatbot on a Website
      • Zapier App
      • GoHighLevel (GHL)
      • Instagram DM
      • Facebook Messenger
      • WhatsApp
      • ElevenLabs Voice
      • Discord
    • 🤖Troubleshooting
      • How to Respond in Any Language
      • Responses are Too Long
      • Debug Mode
      • Clickable Links in Responses
    • 🌌Functions (Labs)
      • Custom Functions
        • How Custom Functions Work
        • Code Generation Prompt for Custom Functions
        • Stock Market Data - Custom Function
        • Shopify - Custom Function
        • Airtable - Custom Function
        • Google Sheets - Custom Function
    • 🔄Vault
      • OpenAI API Key (ChatGPT)
      • Anthropic API Key (Claude)
      • xAI API Key (Grok)
      • Eleven Labs API Key
  • 👑MasterChat
  • White Label
    • 🤑What is White Labeling?
    • 👤Client Sub-Accounts
      • Create Sub-Account
      • Sub-Account Wallet
      • Sub-Account Storage Balance
      • Sub-Account Extra AI Agents
      • How to clone a chatbot to a sub-account
    • 🔗Custom Domain
      • Troubleshooting Custom Domain Deployment DNS Issues
    • 🏗️The SaaS Configurator
      • Create Subscription Package
        • Custom Packages + Settings
      • Add-Ons
        • Storage (Characters) - Add Ons
        • AI Agent Rebilling - Add Ons
        • MasterChat - Add Ons
        • Advanced Scraper - Add Ons
    • 👍White Label API
      • API Documentation
      • AI Agent API
        • Message AI Agent
        • Create AI Agent
        • Retrieve AI Agent
        • Update AI Agent
        • Delete AI Agent
      • Knowledge Base API
        • Add AI Agent Q/A
        • Add URLs to Scrape
        • Add Files (Pdf, Doc etc.)
      • Conversations
        • AI Agent Conversations
        • Retrieve Conversation
        • Delete A Conversation
      • Sub-Accounts
        • Create Sub-Account
        • Retrieve Sub-Account
        • Update Sub-Account
        • Delete Sub-Account
      • User
        • Retrieve User's Data
      • Examples
        • Create New Sub-Account (Zapier Example)
        • White Label API x Zapier X Slack Example
        • AI Chatbot Chrome Extension
    • 👾White Label (Your) Marketplace
    • 😇White Label Free Trials
      • Free Trial Settings (No CC Req.)
      • Free Trial Settings (CC Req.)
    • 🎨Custom Dashboard Styling
  • Agency Settings
    • ⛳Agency Dashboard
    • 👥User Permissions
    • 😎Agency Profile
    • 👥User Access
    • 💳Connect Stripe
    • 🔗Custom Menu Links
    • 🤘Default Prompts
  • Account Management
    • ⚙️Billing Usage & Settings
    • 💲Agency Billing
      • Subscription Plans
      • Change Subscription Plan
      • Update Credit Card
      • Download Invoice
      • Refunds
      • Cancel Subscription
    • 💱Agency Wallet
      • The Agency Wallet System
      • Agency vs Sub-Account Wallet
      • Auto Billing
      • Add Funds to Wallet
      • AI Messages Costs
      • AI Agents Costs
      • Storage (Characters) Costs
    • 🤲Admin Account Profile
      • Change Password
      • Google Auth Login
  • Support
    • 🤝Need Help?
    • 🔓Security & Compliance
      • Data Privacy & Security Report
      • GDPR
      • Terms & Conditions
      • Privacy Policy
      • Data Processing Agreement
      • AI Model Data Usage
      • Service Level Agreement
    • ⚡Discord Community
    • 📹Weekly Office Hours
    • 🙌FAQ
      • General
      • Localization
      • Data/Security
      • Set Up
      • Password
      • Technical Questions
      • Sales/Onboarding
      • Marketing/Pricing
      • Where can I find...?
      • Other
      • Alternatives to Stripe Connect
    • 📰Changelog/ Roadmap
    • 🍭Resources
      • Sales Deck
      • 💰AI Agency 101
        • How to Price Your AI Chatbots
        • How to Get More Clients
        • The Value Proposition of AI Agents
        • AI SaaS Funnel Explained
    • 🤑Affiliate Program
Powered by GitBook
On this page
  1. AI Features
  2. Integrations

Discord

This tutorial shows how to setup a Discord bot with Stammer.ai and Replit.

PreviousElevenLabs VoiceNextTroubleshooting

Last updated 7 months ago

4 Items are Needed for this tutorial:

  1. Discord Bot Token

  2. API Key from Stammer.ai

  3. Chatbot UUID from Stammer.ai

  4. (Optional) White Label URL from Stammer.ai

Instructions

1. Set up Discord account and server: - Create a Discord account (if you don’t have one) - Create a new server or use an existing one

3. Get bot token: - In “Bot” tab, find token section - Click “Copy” to copy bot token to paste into Replit - Keep this token secret!

4. Invite bot to server: - Go to “OAuth2" tab - In “Scopes” section, select “bot” - Choose desired permissions - Copy generated URL and open in new tab - Select server and authorize bot on the channels you want it to access

5. Create New Replit: - Create new Python file - Paste in the template code - Paste in the Discord bot code on line 68 - Update the Stammer Authorization key on line 10 - Update the chatbot UUID on line 11 - (Optional) Update the URL to be your white label API URL on line 14

6. Running the AI Agent: - Run the code in Replit - Go to your Discord channel and ask your bot a question by tagging its name

Code for Replit:

import discord
from discord.ext import commands
import requests

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

stoken = 'YOUR-STAMMER-KEY'
chatbot_uuid = 'SOME_UUID'

def send_message_to_ai_agent(message):
    url = "https://app.stammer.ai/en/chatbot/api/v1/message/"
    headers = {
        'Authorization': f'Token {stoken}',
        'Content-Type': 'application/json'
    }
    data = {
        "chatbot_uuid": chatbot_uuid,
        "query": message,
        "user_key": "discord_user",  # You can change this if needed
    }

    try:
        response = requests.post(url, headers=headers, json=data)
        response.raise_for_status()

        if response.status_code == 200:
            return response.json().get('data', {}).get('answer', 'No response from AI agent.')
        else:
            return f"Unexpected response: {response.text}"

    except requests.exceptions.RequestException as e:
        return f"Error: {str(e)}"

@bot.event
async def on_ready():
    print(f'{bot.user} has connected to Discord!')

@bot.event
async def on_message(message):
    # Ignore messages sent by the bot itself
    if message.author == bot.user:
        return

    # Check if the bot is mentioned in the message
    if bot.user.mentioned_in(message):
        # Get the content of the message without the bot mention
        content = message.content.replace(f'<@!{bot.user.id}>', '').strip()
        content = content.replace(f'<@{bot.user.id}>', '').strip()

        if content:
            # Send the message to the AI agent and get the response
            ai_response = send_message_to_ai_agent(content)
            await message.channel.send(ai_response)
        else:
            await message.channel.send("You mentioned me, but didn't say anything!")

    # Process commands if any
    await bot.process_commands(message)

@bot.command(name='hello')
async def hello(ctx):
    await ctx.send('Hello World!')

# Replace 'YOUR_BOT_TOKEN' with your actual bot token
bot.run('YOUR_DISCORD_BOT_TOKEN')

2. Create Discord application: - Go to - Click “New Application” - Name your application - Go to “Bot” tab and click “Add Bot”

🧊
https://discord.com/developers/applications