Using Discord and Elastic Agent Builder A2A to build a gaming community support bot

Learn how to connect Discord to Elastic Agent Builder's Agent-to-Agent (A2A) server to create a gaming community support bot.

Agent Builder is available now GA. Get started with an Elastic Cloud Trial, and check out the documentation for Agent Builder here.

In this article, we'll build a gaming community support bot that connects Discord to Elastic Agent Builder's Agent-to-Agent (A2A) server. Players will ask questions like, "Who's the best Mage?" or "What's the current meta?" and get real-time answers powered by Elasticsearch Query Language (ES|QL) analytics and semantic search.

Many gaming companies already use Elasticsearch for player data and game analytics. In this tutorial, we'll access that data through Discord, where many users spend their time.

Prerequisites

What we're building

We'll create a Discord bot that uses Elastic Agent Builder's A2A server to answer player questions. The bot will have two types of tools:

  • ES|QL tools for analytics: leaderboards, hero stats, meta reports.
  • Index search tools for knowledge: game mechanics, FAQs.

The architecture looks like this:

Architecture overview

Elastic Agent Builder provides an A2A server to connect with clients. This server exposes the agent with tools that can query Elasticsearch using ES|QL or index search tools. Any A2A-compatible client can connect to it.

The A2A client instantiates a bot that can connect to the Discord server, communicate with Agent Builder, and receive/send messages to the users.

Why A2A instead of MCP?

Agent Builder also offers the option to expose the agent's tools via a Model Context Protocol (MCP) server. The key difference is that with MCP, the client can only access the tools and their descriptions, not the agent itself. Additionally, tool selection logic must be implemented on the MCP client side, since all tools from all agents are exposed together.

With A2A, the entire agent, including instructions and tools, is available to the client. This gives you more control from the Agent Builder side, letting you manage behavior centrally rather than in each client.

The right choice depends on where you want that control to live. For this Discord bot, we want to manage the agent's behavior from Elastic, so A2A is the better fit.

Setting up sample game data

Let's create gaming data that our bot can query. We'll set up three indices:

  • player_stats: Player profiles with wins, kills, rank.
  • hero_meta: Hero pick rates and win rates by tier.
  • game_knowledge: FAQs and game mechanics. Uses semantic_text for meaning-based versus keyword matching. Both title and content are copied into semantic_field for a hybrid search solution.

Create the indices

Index sample data

Done! Now we have data to query.

Creating ES|QL tools via API

Instead of using the UI, we'll create tools programmatically using the Agent Builder API. This makes it easier to version control and deploy.

First, let's set up our Kibana API connection:

Tool 1: Leaderboard

This tool shows top players by kills. We use ES|QL for aggregations:

Tool 2: Hero stats

The hero stats tool returns performance stats for a specific hero using a dynamic parameter:

?hero is a dynamic parameter. When the agent calls this tool, it fills in the hero name from the user's question, bridging natural language, “Is Mage strong?” to structured queries, like | WHERE hero_name == “Mage”.

Tool 3: Meta report

This tool shows which heroes are dominating the current patch:

Adding index search tools

For unstructured content, like FAQs and game mechanics, we use index search tools. The pattern parameter specifies which Elasticsearch index to search:

Keep in mind that ES|QL tools are for structured analytics ("Who has the most kills?"), while index search tools are for unstructured knowledge ("How do I unlock the dragon mount?").

Creating the agent

Let’s create an agent that uses these tools:

The agent now has access to all our tools and can choose one on the user's question.

You can test the connectivity by visiting the Kibana Agent Chat GUI or by sending an API call. By default, Agent Builder uses the Elastic Managed LLM, so no connector configuration is required:

Setting up a Discord bot

If you don't have a Discord bot yet, you'll need to create one following these steps:

1. Go to the Discord Developer Portal.

2. Click New Application, and give it a name.

3. Go to the Bot section, and click Add Bot.

4. Copy the bot token. (You'll need this later.)

5. Under Privileged Gateway Intents, enable Message Content Intent.

6. Go to OAuth2 > URL Generator, select bot and application.commands scopes and Send Messages + Read Message History permissions.

7. Use the generated URL to invite the bot to your server.

Security considerations

On the Discord side, request only the minimum permissions:

  • Send Messages.
  • Send Messages in Threads.
  • Read Message History.
  • Create Polls.

This limits what the bot can do if compromised.

On the Elastic side, create an API key with restricted privileges. For this bot, you only need read access to the game indices:

Configuring the Discord A2A client

The next step is to connect Discord to Agent Builder. We'll use a modified version of the kagent-a2a-discord.

Clone and setup

Environment variables

Create an .env file in the root directory:

Run with Python

The bot should come online in your Discord server within a few seconds.

Testing the bot

Let's test with different query types.

Analytics queries (ES|QL)

User: "Who is the best Mage player?"

Bot: Based on the leaderboard data, ShadowMage is currently the best Mage player in the game. They've reached Master rank with an impressive 8,932 kills and 567 wins…

User: "What's the current meta?"

Bot: The current meta is dominated by Mage, which stands alone in S-tier with an impressive 54.7% win rate and 22.8% pick rate in patch 2.4.1.

Semantic queries (index search)

User: "How do I unlock the dragon mount?"

Bot: To unlock the Dragon Mount, you need to:

  1. Complete the Dragon's Lair dungeon on Nightmare difficulty.
  2. Keep all party members alive throughout the entire run.
  3. Cross your fingers for luck - the mount has a 15% drop rate…

The bot automatically picks the right tool based on the question.

Bidirectional: Giving the agent actions

Beyond answering questions, we can give Agent Builder the ability to trigger Discord actions. With a small modification to the Discord client, we can parse special tags in the agent's response and execute Discord commands.

For example, we added support for a <poll> tag:

When the agent includes this in its response, the bot creates a native Discord poll. The agent just needs instructions on when to use it. Run the following to add to the instructions:

Now when a user asks "Is Mage overpowered?" the agent can share the stats and create a poll, turning data insights into community engagement.

The same pattern works for other Discord features, like reactions, role mentions, or scheduled announcements. The agent's response becomes a control channel for Discord actions.

Conclusion

In this article, we successfully built a Discord bot using Elastic Agent Builder's A2A server. The process covered creating ES|QL tools via API for analytics, such as leaderboards, hero stats, and meta reports, and developing index search tools for semantic search against a knowledge base. Furthermore, we demonstrated the use of dynamic parameters, like ?hero for flexible queries, established the connection between Discord and the A2A client, and tested both analytics and semantic query types.

The Agent Builder provides the A2A server, so you only need to focus on creating tools and connecting clients, while ES|QL handles structured analytics and index search handles unstructured knowledge.

Resources

Related Content

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as you are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself