Documentation Index
Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
Use this file to discover all available pages before exploring further.
Build a Discord bot with tools and persistent memory.
Create the bot
- Go to the Discord Developer Portal
- Click New Application and name it
- Go to Bot and click Add Bot
- Enable MESSAGE_CONTENT under Privileged Gateway Intents
- Copy the bot token
- Use the OAuth2 URL Generator to invite the bot (select
bot scope with Send Messages and Read Message History)
Create the agent
import asyncio
import os
from definable.agent import Agent
from definable.agent.interface import DiscordInterface
from definable.memory import Memory, SQLiteStore
from definable.tool.decorator import tool
@tool
def search_docs(query: str) -> str:
"""Search documentation for an answer."""
return f"Found results for: {query}"
agent = Agent(
model="gpt-4o",
instructions="You are a helpful Discord bot.",
tools=[search_docs],
memory=Memory(store=SQLiteStore("./discord_memory.db")),
)
discord = DiscordInterface(
agent=agent,
bot_token=os.environ["DISCORD_BOT_TOKEN"],
)
asyncio.run(discord.serve_forever())
Install dependencies
pip install 'definable[discord]'
Set environment variables
export DISCORD_BOT_TOKEN="your-bot-token"
export OPENAI_API_KEY="sk-..."
Run
Mention the bot or send a DM to start chatting.
See Discord reference for all configuration options.