Skip to main content

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

Dalamud.Plugin.Services

Events

ChatMessage

public event OnMessageDelegate ChatMessage;
Fired when a chat message is sent to chat by the game.
type
XivChatType
The type of chat
timestamp
int
The timestamp of when the message was sent
sender
SeString
The sender name (ref parameter)
message
SeString
The message sent (ref parameter)
isHandled
bool
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.
type
XivChatType
The type of chat
timestamp
int
The timestamp of when the message was sent
sender
SeString
The sender name (ref parameter)
message
SeString
The message sent (ref parameter)
isHandled
bool
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.
type
XivChatType
The type of chat
timestamp
int
The timestamp of when the message was sent
sender
SeString
The sender name
message
SeString
The message sent

ChatMessageUnhandled

public event OnMessageUnhandledDelegate ChatMessageUnhandled;
Fired when a chat message is not handled by Dalamud or a plugin.
type
XivChatType
The type of chat
timestamp
int
The timestamp of when the message was sent
sender
SeString
The sender name
message
SeString
The message sent

LogMessage

public event OnLogMessageDelegate LogMessage;
Fired when a log message (based on entries in the LogMessage sheet) is sent.
message
ILogMessage
The log message

Properties

LastLinkedItemId

public uint LastLinkedItemId { get; }
Gets the ID of the last linked item.
LastLinkedItemId
uint
The item ID

LastLinkedItemFlags

public byte LastLinkedItemFlags { get; }
Gets the flags of the last linked item.
LastLinkedItemFlags
byte
The item flags

RegisteredLinkHandlers

public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers { get; }
Gets the dictionary of Dalamud link handlers.
Dictionary of registered link handlers

Methods

AddChatLinkHandler

public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction);
Registers a chat link handler.
commandId
uint
required
The ID of the command
commandAction
Action<uint, SeString>
required
The action to be executed
return
DalamudLinkPayload
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.
commandId
uint
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
messageTag
string
String to prepend message with “[messageTag] ”
tagColor
ushort
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
messageTag
string
String to prepend message with “[messageTag] ”
tagColor
ushort
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();
    }
}

Remarks

  • 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

Build docs developers (and LLMs) love