Integrating kagent with Discord
Kagent enables you to create AI agents that run inside your Kubernetes cluster. They can access a variety of built-in tools, fetch data from your memory, and use other external tools via MCP.
This guide shows how to connect a Discord bot to one of your agents using the A2A protocol, enabling natural conversations and command execution inside Discord.
GitHub Repository: lekkerelou/kagent-a2a-discord

We’ll walk through:
- Setting up a Discord bot.
- Connecting it to a kagent agent via A2A.
- Running and testing the integration locally or in Docker.
Creating a Discord Bot
- Visit the Discord Developer Portal
- Click New Application, give it a name, and save.
- Go to the Bot tab → Reset Token and save the Discord Bot Token
- Under Privileged Gateway Intents, enable Message Content Intent. This allows the bot to receive Discord message content.
- Copy your bot token, you'll need it for your
.env
file.
Under the OAuth2 → OAuth2 URL Generator, check:
bot
under scopesSend Messages
,Read Message History
under bot permissions


Make sure the "Integration Type" is set to Guild Install.
Use the generated URL to invite your bot to your server.
Setting up the bot code
- Clone the repository:
git clone https://github.com/lekkerelou/kagent-a2a-discord.gitcd kagent-a2a-discord
- Copy the example environment file and fill in your values:
cp .env.example .env
Edit .env
:
DISCORD_BOT_TOKEN=your_tokenKAGENT_A2A_URL=http://127.0.0.1:8083/api/a2a/kagent/my-k8s-agent
- Create and activate a virtual environment:
uv venv
- Install dependencies:
uv sync
- Run the bot:
uv run main.py# orpython main.py
You should see logs indicating the bot is online.
Running with Docker
If you prefer Docker, you can use the pre-built image:
docker pull ghcr.io/lekkerelou/kagent-a2a-discord:latestdocker run --env-file .env ghcr.io/lekkerelou/kagent-a2a-discord:latest
You can also build the image locally if needed:
docker build -t a2a-discord-bot .docker run --env-file .env a2a-discord-bot
Bot Behavior
The bot listens to messages in all channels unless restricted by environment variables.
Optional .env
keys
You can customize the bot's behavior with the following optional environment variables:
DISCORD_MENTION_ONLY
: Set totrue
to make the bot respond only when mentioned.DISCORD_CHANNEL_ONLY
: A comma-separated list of channel IDs where the bot is allowed to respond.
When a message is received, it’s sent to the A2A endpoint (KAGENT_A2A_URL
), and the agent’s response is posted back in Discord.
Agent Setup
If you haven’t deployed your agent yet, follow the instructions in Deploying an Agent. You can reuse the same agent across Slack and Discord integrations.
Be sure to port-forward your agent if running locally:
kubectl port-forward -n kagent svc/kagent-service 8083:8083
Set KAGENT_A2A_URL
accordingly in your .env
:
http://127.0.0.1:8083/api/a2a/kagent/my-k8s-agent
Conclusion
You now have a working Discord bot connected to your kagent agent via A2A. From here, you can:
- Customize the bot behavior
- Extend the agent with new tools
- Deploy in production
For questions or support, join our Discord community, or open an issue on GitHub.