Skip to content

ChatMessageEvent

Triggered when a message goes into the chat for all players: what a player writes there, and a /say or /me of anyone who can run the command, be it a player, another entity, a spell, a command block or the console. kind tells which, and sender who sent it.

A whisper with /msg and a team message with /teammsg go to some players only and don't trigger this event. Bots get them as a BotMessageEvent.

This event can be canceled to prevent the message from being distributed.

Example: Suppressing chat messages from a specific player

local i = spell:intercept({ "ChatMessageEvent" }, function(evt)
  if evt.senderName == "mickkay" then
    return false -- cancel the event
  end
end)

while true do sleep(20) end -- Keep the spell active

Example: Who said what

local queue = spell:collect("ChatMessageEvent")
while true do
  local evt = queue:next() --[[@as ChatMessageEvent]]
  if instanceOf(Spell, evt.sender) then
    print("The spell " .. evt.senderName .. " says: " .. evt.message)
  elseif instanceOf(Player, evt.sender) then
    print(evt.senderName .. " writes: " .. evt.message)
  end
end

Fields

kind: "chat"|"say"|"emote" — Read-Only

What the message is: "chat" for what a player writes in the chat, "say" for a /say, "emote" for a /me.

message: string — Read-Only

The content of the chat message, without the name in front of it.

name: string — Read-Only

The name of the event, identifying it as a chat message event.

sender: Entity|Spell|nil — Read-Only

A reference to who sent the message: the player; the entity that the command ran as, like a zombie with /execute as ... run say; or the spell that ran the command. nil for a command block and the console.

senderName: string — Read-Only

The name the message comes with: the name of the player, the entity or the spell, "@" for a command block, or "Server" for the console.