Violet

Chat

On this page

Read chat as it appears in the chat window, and send chat messages from a script.

Receiving

on_chat(sender: string, message: string, channel: string, type: number)

Called for every chat message the client displays. sender is the IGN that sent it (empty for system lines), message is the text, channel is the channel it arrived on, and type is the client's raw chat-log type code (handy for telling megaphone sub-kinds apart on your client build).

This callback is observe-only — it cannot block or modify the message.

channelSource
"public"Normal map chat (anyone speaking in your field)
"whisper"Whisper / private message
"party"Party chat
"buddy"Buddy (friend) chat
"guild"Guild chat
"alliance"Alliance chat
"megaphone"World / super megaphone
Info

System notices, item-drop messages and other non-chat log lines are not reported. Your own outgoing messages are included.

Sending

core.chat.send(message: string, channel?: string) -> boolean

Sends a chat message. channel defaults to "public"; valid values are "public", "party", "buddy", "guild", and "alliance". Returns true on success, or false plus an error string.

Warning

For "public", a message beginning with / is sent as a chat command — exactly as if you had typed it into the chat box.

core.chat.whisper(target: string, message: string) -> boolean

Whispers message to the player named target. Returns true on success, or false plus an error string (target/message empty, or not currently in a field). This is the scripted equivalent of typing the whisper into the chat box, so the client applies its normal rules — you must be in a field, and whispering yourself is ignored by the game.

Plugin Required

on_chat must be part of a plugin with proper metadata structure.

Example

lua
plugin = {
    name = "Chat Logger",
    author = "YourName",
    version = "1.0",
    description = "Logs chat and auto-replies to whispers",
    load = true
}

function on_chat(sender, message, channel, type)
    core.log(string.format("[%s] %s: %s", channel, sender, message))

    if channel == "whisper" then
        core.chat.whisper(sender, "Auto-reply: I'm busy right now!")
    end
end