Basic

Discord Bot Run an Agno agent as a Discord bot with DiscordClient.

basic.py
"""
Discord Bot
Run an Agno agent as a Discord bot with DiscordClient.

Prerequisites: OPENAI_API_KEY, DISCORD_BOT_TOKEN, and a Discord bot with
message-content intent and thread permissions enabled.
Run: .venvs/demo/bin/python cookbook/integrations/discord/basic.py
Try: Send the bot a direct message or mention it in a server channel.
"""

import discord
from agno.agent import Agent
from agno.integrations.discord import DiscordClient
from agno.models.openai import OpenAIResponses

# ---------------------------------------------------------------------------
# Create Discord Bot
# ---------------------------------------------------------------------------

discord_assistant = Agent(
    name="Discord Assistant",
    model=OpenAIResponses(id="gpt-5.5"),
    add_history_to_context=True,
    num_history_runs=3,
)

discord_intents = discord.Intents.default()
discord_intents.message_content = True
discord_bot = discord.Client(intents=discord_intents)
discord_client = DiscordClient(agent=discord_assistant, client=discord_bot)

# ---------------------------------------------------------------------------
# Run Discord Bot
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    discord_client.serve()

Message handling and history

DiscordClient handles messages in channels the bot can access, including messages that do not mention it. It skips messages from itself. Restrict its channel access or add an application-level mention filter if you want narrower behavior.

The recipe has no database, so add_history_to_context=True alone does not retain earlier runs. To enable the configured three-run history, add a database to the agent before constructing DiscordClient:

from agno.db.sqlite import SqliteDb

discord_assistant.db = SqliteDb(db_file="tmp/discord.db")

Install sqlalchemy for this addition. Discord supplies the user identity and the channel or thread session ID on each run.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno discord.py openai

Export environment variables

export DISCORD_BOT_TOKEN="your_discord_bot_token_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Configure the Discord bot

Enable the Message Content privileged intent. Install the bot with View Channels, Send Messages, Read Message History, Create Public Threads, and Send Messages in Threads permissions.

Run the example

Save the code above as basic.py, then run:

python basic.py

Full source: cookbook/integrations/discord/basic.py