ChatCommandAPI
A Lethal Company modding API for easy creation of Minecraft-style Chat Commands
About this mod Author’s original text
This is a mod for developers
You probably won't find much on this page as a player.
Instead, try checking out the page of the mod that brought you here
If you encounter any issues while playing or creating a mod with this API,
or you would like to request a new feature,
please open an issue on GitHub.
This mod is open-source, you can contribute to it
by opening a pull request
Getting started
- Include API in your project
Simply run dotnet add package baer1.ChatCommandAPI or add the following line to your csproj file:
Additionally, you should reference this mod in both your main plugin class and your manifest.json:
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency(ChatCommandAPI.MyPluginInfo.PLUGIN_GUID)]
public class ExampleMod: BaseUnityPlugin;
{
"dependencies": [
"BepInEx-BepInExPack-5.4.2305",
"baer1-ChatCommandAPI-1.2.1"
]
}
- Create Command Subclass
Simply create a non-static class that inherits the ChatCommandAPI.Command class.
The Invoke method contains the logic that will be run.
The default command name is the class name you assign to it, ExampleCommand in the example below.
You can run this command through the in-game chat. \(See below for changing it\)
This mod is case-insensitive \(/eXaMpLeCoMmAnD is valid\)
Example:
using ChatCommandAPI;
namespace ExampleMod;
public class ExampleCommand: Command
{
public override void Invoke(string args)
{
// Put your code here
return;
}
}
- Instantiate the Subclass _once_
using BepInEx;
namespace ExampleMod;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency(ChatCommandAPI.MyPluginInfo.PLUGIN_GUID)]
public class ExampleMod: BaseUnityPlugin
{
private void Awake()
{
_ = new ExampleCommand();
}
}
- Done!
You can now use the command /examplecommand in-game to run the function defined
in Step 2
Advanced usage
Customizing the command
You can overwrite several properties of the Command class to customize your command:
using ChatCommandAPI;
using ChatCommandAPI.Utils;
namespace ExampleMod;
public class ExampleCommand: Command
{
public override string Name => "My command"; // Display name
public override string Description => "Prints Hello World [amount] times"; // Short description
public override string Command => "examplecommand"; // Primary command
public override string Aliases => ["ex", "example"]; // Aliases (an alias may become the primary to avoid duplicates)
public override string Syntax => ["[amount]"]; // All valid syntaxes for this command (only for help, not validated)
public override bool Hidden => false; // Whether to hide this command from the help list (useful for debugging, default: false)
public override void Invoke(string args)
{
ushort amount = 1;
if (args.Length > 0)
if (!ushort.TryParse(args, out amount))
throw new InvalidArgumentsException(); // Report "Invalid arguments"
while (amount > 0)
{
Chat.Print("Hello, World!");
amount--;
}
}
}
The above results in the following being displayed on the help list:
My command - Prints Hello World [amount] times
/examplecommand [amount]
Server commands
Server commands are commands that anyone on the server can use, as long as the host has them installed.
They are very similar to the client commands.
Example (simple implementation of the ShipLoot mod as a server command):
using System.Linq;
using GameNetcodeStuff;
using UnityEngine;
using ChatCommandAPI;
using ChatCommandAPI.Utils;
namespace ExampleMod;
public class ShipLoot: ServerCommand
{
public override string Description => "Displays the value of all loot on the ship";
public override void Invoke(
PlayerControllerB caller, // Player that sent the command
string args
)
{
// We need the ship to calculate the value of the loot on it
var ship = GameObject.Find("/Environment/HangarShip");
if (ship == null)
throw new CommandException("Ship not found"); // Report "Ship no
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: