Overview
IChatGui handles interacting with the native chat UI. It allows plugins to send messages to chat, intercept incoming messages, and register custom chat link handlers.
Namespace
Events
ChatMessage
public event OnMessageDelegate ChatMessage;
Fired when a chat message is sent to chat by the game.
The timestamp of when the message was sent
The sender name (ref parameter)
The message sent (ref parameter)
A value indicating whether the message was handled or should be propagated (ref parameter)
CheckMessageHandled
public event OnCheckMessageHandledDelegate CheckMessageHandled;
Allows you to stop messages from appearing in chat by setting the isHandled parameter to true.
The timestamp of when the message was sent
The sender name (ref parameter)
The message sent (ref parameter)
Set to true to prevent the message from appearing (ref parameter)
ChatMessageHandled
public event OnMessageHandledDelegate ChatMessageHandled;
Fired when a chat message is handled by Dalamud or a plugin.
The timestamp of when the message was sent
ChatMessageUnhandled
public event OnMessageUnhandledDelegate ChatMessageUnhandled;
Fired when a chat message is not handled by Dalamud or a plugin.
The timestamp of when the message was sent
LogMessage
public event OnLogMessageDelegate LogMessage;
Fired when a log message (based on entries in the LogMessage sheet) is sent.
Properties
LastLinkedItemId
public uint LastLinkedItemId { get; }
Gets the ID of the last linked item.
LastLinkedItemFlags
public byte LastLinkedItemFlags { get; }
Gets the flags of the last linked item.
RegisteredLinkHandlers
public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers { get; }
Gets the dictionary of Dalamud link handlers.
RegisteredLinkHandlers
IReadOnlyDictionary<(string, uint), Action<uint, SeString>>
Dictionary of registered link handlers
Methods
AddChatLinkHandler
public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction);
Registers a chat link handler.
commandAction
Action<uint, SeString>
required
The action to be executed
An SeString payload for the link
RemoveChatLinkHandler
public void RemoveChatLinkHandler(uint commandId);
public void RemoveChatLinkHandler();
Removes a chat link handler. The parameterless overload removes all chat link handlers registered by the plugin.
The ID of the command to remove
Print
public void Print(XivChatEntry chat);
public void Print(string message, string? messageTag = null, ushort? tagColor = null);
public void Print(SeString message, string? messageTag = null, ushort? tagColor = null);
public void Print(ReadOnlySpan<byte> message, string? messageTag = null, ushort? tagColor = null);
Queues a chat message. Dalamud will send queued messages on the next framework event.
message
string | SeString | ReadOnlySpan<byte> | XivChatEntry
required
The message to send
String to prepend message with “[messageTag] ”
Color to display the message tag with
PrintError
public void PrintError(string message, string? messageTag = null, ushort? tagColor = null);
public void PrintError(SeString message, string? messageTag = null, ushort? tagColor = null);
public void PrintError(ReadOnlySpan<byte> message, string? messageTag = null, ushort? tagColor = null);
Queues an error chat message. Dalamud will send queued messages on the next framework event.
message
string | SeString | ReadOnlySpan<byte>
required
The message to send
String to prepend message with “[messageTag] ”
Color to display the message tag with
Example Usage
public class MyPlugin : IDalamudPlugin
{
private readonly IChatGui chatGui;
public MyPlugin(IChatGui chatGui)
{
this.chatGui = chatGui;
// Subscribe to chat messages
this.chatGui.ChatMessage += OnChatMessage;
// Register a custom link handler
var payload = this.chatGui.AddChatLinkHandler(1, OnLinkClick);
// Send a message with a link
var message = new SeStringBuilder()
.AddText("Click ")
.Add(payload)
.AddText("here")
.Add(RawPayload.LinkTerminator)
.AddText(" for more info")
.Build();
this.chatGui.Print(message);
}
private void OnChatMessage(
XivChatType type,
int timestamp,
ref SeString sender,
ref SeString message,
ref bool isHandled)
{
// Filter specific chat types
if (type == XivChatType.Say)
{
Log.Information($"{sender.TextValue} says: {message.TextValue}");
}
}
private void OnLinkClick(uint commandId, SeString message)
{
this.chatGui.Print("Link clicked!");
}
public void Dispose()
{
this.chatGui.ChatMessage -= OnChatMessage;
this.chatGui.RemoveChatLinkHandler();
}
}
- Messages are queued and sent on the next framework update
- Always unsubscribe from events and remove link handlers in your plugin’s
Dispose() method
- The
CheckMessageHandled event allows you to filter messages before they appear in chat
- SeString allows for rich formatting including colors, icons, and links