2022-11-28 14:10:55 +08:00
---
2022-11-05 13:43:19 +08:00
title: Creating Chat Bots
2022-11-05 13:30:46 +08:00
---
2022-11-06 16:20:38 +08:00
2022-11-02 21:01:32 +08:00
# Creating Chat Bots
2026-03-25 16:58:16 +00:00
- [Notes ](#notes )
- [Requirements ](#requirements )
- [Quick Introduction ](#quick-introduction )
- [Examples ](#examples )
- [AI-Assisted Bot Authoring ](#ai-assisted-bot-authoring )
2026-03-30 23:45:35 +00:00
- [Achievements And Advancements ](#achievements-and-advancements )
2026-03-25 16:58:16 +00:00
- [C# API ](#c#-api )
2022-11-02 21:01:32 +08:00
## Notes
2026-03-27 13:45:45 +00:00
< div class = "custom-container note" > < p class = "custom-container-title" > Note< / p >
2022-11-04 14:25:59 +08:00
2026-03-22 15:40:05 +01:00
**This page covers the basics of the Chat Bot API. For the full surface area, read [ChatBot.cs ](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/MinecraftClient/Scripting/ChatBot.cs ) and the example scripts linked below.**
2022-11-04 14:25:59 +08:00
2022-11-04 15:22:53 +08:00
< / div >
2022-11-02 21:01:32 +08:00
**Minecraft Console Client** has a rich C# API which allows you to create Chat Bots (effectively plugins) which can help you create complex automations which normal scripts may not be able to do.
## Requirements
2026-03-25 16:58:16 +00:00
- A basic knowledge of C# programming language
- A text editor
2022-11-02 21:01:32 +08:00
If you're not familiar with the C# programming language, we suggest taking a look at the following resources:
Crash courses:
2026-03-25 16:58:16 +00:00
- [C# Crash Course playlist by Teddy Smit ](https://www.youtube.com/watch?v=67oWw9TanOk&list=PL82C6-O4XrHfoN_Y4MwGvJz5BntiL0z0D )
2022-11-02 21:01:32 +08:00
More in-depth:
2026-03-25 16:58:16 +00:00
- [Learn C# YouTube Playlist by Microsoft ](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oVxKLQCHpiUWun7vlJJvUiN )
- [Getting started with C# (an index of tutorials and documentation) by Microsoft ](https://learn.microsoft.com/en-us/dotnet/csharp/ )
2022-11-02 21:01:32 +08:00
## Quick Introduction
This introduction assumes that you have the basic knowledge of C#.
2026-03-27 13:45:45 +00:00
< div class = "custom-container note" > < p class = "custom-container-title" > Note< / p >
2022-11-04 14:25:59 +08:00
2026-03-22 15:40:05 +01:00
**In this page, "Chat Bot" and "Script" are used interchangeably.**
2022-11-04 14:25:59 +08:00
2022-11-04 15:22:53 +08:00
< / div >
2022-11-02 21:01:32 +08:00
Create a new empty file and name it `ExampleChatBot.cs` in the same folder where you have your MCC installed.
Paste the following example code:
```csharp
//MCCScript 1.0
MCC.LoadBot(new ExampleChatBot());
//MCCScript Extensions
// The code and comments above are defining a "Script Metadata" section
2026-03-22 15:40:05 +01:00
// Every chat bot script must define a class that extends ChatBot.
// Instantiate that class in the script metadata section and pass it to MCC.LoadBot.
2022-11-02 21:01:32 +08:00
class ExampleChatBot : ChatBot
{
// This method will be called when the script has been initialized for the first time, it's called only once
// Here you can initialize variables, eg. Dictionaries. etc...
public override void Initialize()
{
LogToConsole("An example Chat Bot has been initialized!");
}
// This is a function that will be run when we get a chat message from a server
// In this example it just detects the type of the message and prints it out
public override void GetText(string text)
{
string message = "";
string username = "";
text = GetVerbatim(text);
if (IsPrivateMessage(text, ref message, ref username))
{
LogToConsole(username + " has sent you a private message: " + message);
}
else if (IsChatMessage(text, ref message, ref username))
{
LogToConsole(username + " has said: " + message);
}
}
}
```
Start MCC, connect to a server and run the following internal command: `/script ExampleChatBot.cs` .
2026-03-22 15:40:05 +01:00
If everything worked, you should see `[Example Chat Bot] An example Chat Bot has been initialized!` in the console.
2022-11-02 21:01:32 +08:00
### Structure of Chat Bots
Chat Bot (Script) structure is the following:
```
< script metadata >
< chat bot class >
```
**Script Metadata** is a section with a custom format that mixes in C# with our format using comments.
2022-11-04 16:26:53 +08:00
2022-11-02 21:01:32 +08:00
Every single Chat Bot (Script) must have this section at the beginning in order to work.
### Script Metadata Format
`//MCCScript 1.0` marks the beginning of the **Script Metadata** section, this must always be on the first line or the Chat Bot (Script) will not load and will throw an error.
2026-03-22 15:40:05 +01:00
`//MCCScript Extensions` marks the end of the **Script Metadata** section. It must appear before the Chat Bot class.
2022-11-02 21:01:32 +08:00
2026-03-22 15:40:05 +01:00
To load a Chat Bot script, instantiate the bot class between `//MCCScript 1.0` and `//MCCScript Extensions` , then pass it to `MCC.LoadBot` .
2022-11-02 21:01:32 +08:00
Example code:
```
MCC.LoadBot(new YourChatBotClassNameHere());
```
2026-03-22 15:40:05 +01:00
The **Script Metadata** section also lets you include namespaces and DLL references with `//using <namespace>` and `//dll <dll name>` .
2022-11-02 21:01:32 +08:00
2026-03-27 13:45:45 +00:00
< div class = "custom-container note" > < p class = "custom-container-title" > Note< / p >
2022-11-04 14:25:59 +08:00
2022-11-04 12:04:57 +08:00
**Avoid adding whitespace between `//` and keywords**
2022-11-04 14:25:59 +08:00
2022-11-04 15:22:53 +08:00
< / div >
2022-11-02 21:01:32 +08:00
2026-03-22 15:40:05 +01:00
By default, the following namespaces are loaded:
2022-11-02 21:01:32 +08:00
```csharp
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Threading;
using MinecraftClient;
using MinecraftClient.Mapping;
using MinecraftClient.Inventory;
```
Example:
```csharp
//using System.Collections.Immutable
//dll MyDll.dll
```
Full Example:
```csharp
//MCCScript 1.0
//using System.Collections.Immutable
//dll MyDll.dll
MCC.LoadBot(new ExampleChatBot());
//MCCScript Extensions
```
### Chat Bot Class
2026-03-22 15:40:05 +01:00
After the **Script Metadata** section, you can define any number of helper classes. The main bot class must extend `ChatBot` .
2022-11-02 21:01:32 +08:00
There are no required methods, everything is optional.
2026-03-22 15:40:05 +01:00
When the Chat Bot is initialized for the first time, the `Initialize` method is called.
2022-11-04 16:26:53 +08:00
2026-03-22 15:40:05 +01:00
Use it to initialize state such as dictionaries or cached values.
2022-11-02 21:01:32 +08:00
2026-03-27 13:45:45 +00:00
< div class = "custom-container note" > < p class = "custom-container-title" > Note< / p >
2022-11-04 14:25:59 +08:00
2022-11-04 12:04:57 +08:00
**For allocating resources like a database connection, we recommend allocating them in `AfterGameJoined` and freeing them in `OnDisconnect` **
2022-11-04 14:25:59 +08:00
2026-03-22 15:40:05 +01:00
< / div >
2022-11-02 21:01:32 +08:00
## Examples
2026-03-22 15:40:05 +01:00
You can find more examples in the [ChatBots ](https://github.com/MCCTeam/Minecraft-Console-Client/tree/master/MinecraftClient/ChatBots ) and [config ](https://github.com/MCCTeam/Minecraft-Console-Client/tree/master/MinecraftClient/config ) folders in the GitHub repository.
2022-11-02 21:01:32 +08:00
2026-03-22 15:57:44 +01:00
## AI-Assisted Bot Authoring
If you are using an AI coding agent on this repository, use the `mcc-chatbot-authoring` skill for bot work.
2026-03-22 16:04:45 +01:00
Skill links:
2026-03-25 16:58:16 +00:00
- [Browse the skill on GitHub ](https://github.com/MCCTeam/Minecraft-Console-Client/tree/master/.skills/mcc-chatbot-authoring )
- [Download the skill directory ](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2FMCCTeam%2FMinecraft-Console-Client%2Ftree%2Fmaster%2F.skills%2Fmcc-chatbot-authoring )
2026-03-22 16:04:45 +01:00
2026-03-22 15:57:44 +01:00
This skill is meant for:
2026-03-25 16:58:16 +00:00
- standalone `/script` bots
- built-in MCC chat bots
- bot repairs and ports
- event handlers, movement logic, inventory logic, and plugin-channel work
2026-03-22 15:57:44 +01:00
Its default behavior is important: if you ask for "a bot" without saying otherwise, it should prefer a standalone `//MCCScript` bot loaded with `/script` . It should only choose a built-in bot when you explicitly ask for repo wiring, automatic config loading, or a compiled MCC bot.
The skill also follows MCC-specific rules, for example:
2026-03-25 16:58:16 +00:00
- do not send chat from `Initialize()`
- use `AfterGameJoined()` for chat or commands after login
- normalize chat with `GetVerbatim(text)` before `IsChatMessage(...)` or `IsPrivateMessage(...)`
- fully clean up commands, timers, plugin channels, and movement locks
2026-03-22 15:57:44 +01:00
### Example prompts
```text
Create a standalone MCC /script bot that watches public chat for the word "auction" and logs matching messages to the console. Use the mcc-chatbot-authoring skill.
```
```text
Fix this existing MCC script bot so it stops sending chat from Initialize() and moves the startup command to AfterGameJoined(). Use the mcc-chatbot-authoring skill.
```
```text
Make a built-in MCC chat bot named AutoTorch and wire it fully into the repo config and bot registration. Use the mcc-chatbot-authoring skill.
```
```text
Create a standalone MCC /script bot that follows private messages, uses GetVerbatim(text), and replies only to bot owners. Use the mcc-chatbot-authoring skill.
```
2026-03-30 17:28:15 +02:00
## Achievements And Advancements
Chat bots and C# scripts can read the current achievement state and react to updates.
2026-03-30 23:45:35 +00:00
Methods:
2026-03-30 17:28:15 +02:00
- `GetAchievements()`
- `GetUnlockedAchievements()`
- `GetLockedAchievements()`
- `OnAchievementUpdate(IReadOnlyList<Achievement> updated, IReadOnlyList<string> removedIds, bool reset)`
2026-03-30 23:45:35 +00:00
The `Achievement` record exposes:
- `Id` (`string` ) - resource identifier, e.g. `minecraft:story/root` or `achievement.openInventory`
- `Title` (`string?` ) - display name, or `null` for legacy achievements
- `Description` (`string?` ) - display description, or `null` for legacy achievements
- `Type` (`AchievementType` ) - `Task` , `Challenge` , `Goal` , or `Legacy`
- `IsCompleted` (`bool` ) - whether all requirements have been met
- `IsHidden` (`bool` ) - whether the advancement is hidden in the UI until unlocked
- `Requirements` (`IReadOnlyList<IReadOnlyList<string>>` ) - OR-groups of criteria that must all be satisfied
- `CriteriaProgress` (`IReadOnlyDictionary<string, bool>` ) - per-criterion completion status
Notes:
2026-03-30 17:28:15 +02:00
- On `1.8` to `1.11.2` , ids use the legacy `achievement.*` format.
- On `1.12+` , ids use advancement resource ids such as `minecraft:story/root` .
2026-03-30 23:45:35 +00:00
- Legacy achievements have `Title = null` and `Description = null` because the server does not send display metadata in the statistics packet.
2026-03-30 17:28:15 +02:00
- On newer versions, revoking an advancement may remove it from the current set instead of turning it into a locked entry, so `removedIds` matters.
Example:
```csharp
//MCCScript 1.0
MCC.LoadBot(new AchievementWatcher());
//MCCScript Extensions
public class AchievementWatcher : ChatBot
{
public override void AfterGameJoined()
{
Achievement[] known = GetAchievements();
LogToConsole($"Known achievements: {known.Length}");
}
public override void OnAchievementUpdate(IReadOnlyList< Achievement > updated, IReadOnlyList< string > removedIds, bool reset)
{
LogToConsole($"Achievement update: reset={reset}, updated={updated.Count}, removed={removedIds.Count}");
foreach (Achievement achievement in updated)
{
string title = achievement.Title ?? achievement.Id;
string state = achievement.IsCompleted ? "done" : "todo";
LogToConsole($" - {title}: {state}");
}
foreach (string removedId in removedIds)
LogToConsole($" - removed: {removedId}");
}
}
```
2022-11-02 21:01:32 +08:00
## C# API
2026-03-22 15:40:05 +01:00
The authoritative reference for the C# API is [ChatBot.cs ](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/MinecraftClient/Scripting/ChatBot.cs ).
2022-11-02 21:01:32 +08:00
Each method is well documented with standard C# documentation comments.
2026-03-22 15:40:05 +01:00
This page intentionally stays focused on the basics. For newer hooks and overloads, check the source file directly.