--- title: Creating Chat Bots --- # Creating Chat Bots - [Notes](#notes) - [Requirements](#requirements) - [Quick Introduction](#quick-introduction) - [Examples](#examples) - [AI-Assisted Bot Authoring](#ai-assisted-bot-authoring) - [C# API](#c#-api) ## Notes

Tip

**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.**
**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 - A basic knowledge of C# programming language - A text editor If you're not familiar with the C# programming language, we suggest taking a look at the following resources: Crash courses: - [C# Crash Course playlist by Teddy Smit](https://www.youtube.com/watch?v=67oWw9TanOk&list=PL82C6-O4XrHfoN_Y4MwGvJz5BntiL0z0D) More in-depth: - [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/) ## Quick Introduction This introduction assumes that you have the basic knowledge of C#.

Tip

**In this page, "Chat Bot" and "Script" are used interchangeably.**
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 // 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. 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`. If everything worked, you should see `[Example Chat Bot] An example Chat Bot has been initialized!` in the console. ### Structure of Chat Bots Chat Bot (Script) structure is the following: ```