Jump to content

Modding:Chat Commands: Difference between revisions

From Stardew Valley Wiki
imported>BarleyZP
create page with info from Modding:Migrate to Stardew Valley 1.6.9 (main author Pathoschild)
 
imported>BarleyZP
Format after copy/paste, add "see also"
Line 3: Line 3:
This page documents how custom [[Multiplayer#Chat|chat commands]] are handled by the game. This is an advanced guide for mod developers.
This page documents how custom [[Multiplayer#Chat|chat commands]] are handled by the game. This is an advanced guide for mod developers.


==Copied from [[Modding:Migrate to Stardew Valley 1.6.9]]==
==Registering custom commands==
Chat commands are now modular and extensible in 1.6.9, with a new <samp>ChatCommands</samp> API to manage them.
Chat commands are modular and extensible, with a <samp>ChatCommands</samp> API to manage them.


For example, you can add a custom chat command like this:
For example, you can add a custom chat command like this:
Line 22: Line 22:
</syntaxhighlight>
</syntaxhighlight>


==See also==
* [[Modding:Console commands]] for commands that can be typed in the SMAPI console.


[[Category:Modding]]
[[Category:Modding]]

Revision as of 19:37, 19 May 2025

← Index

This page documents how custom chat commands are handled by the game. This is an advanced guide for mod developers.

Registering custom commands

Chat commands are modular and extensible, with a ChatCommands API to manage them.

For example, you can add a custom chat command like this:

string modId = this.ModManifest.UniqueId;
ChatCommands.Register($"{modId}_echo", this.Echo, name => $"{name} [message]: show the given message in the chat box.");

...

/// <inheritdoc cref="ChatCommandHandlerDelegate" />
private void Echo(string[] command, ChatBox chat)
{
    string message = ArgUtility.GetRemainder(command, 1);

    chat.addInfoMessage(message);
}

See also