# SendMessage

`com.jsmacrosce.jsmacros.client.api.event.impl.EventSendMessage`

**Since:** 1.2.7

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fires for text submitted through the chat screen, before the game normalizes it. Cancelling
prevents sending and chat-history insertion. A changed, nonempty value is sent directly without
normalization or history insertion; `null` or an empty replacement is not sent. A leading
`/` selects command submission, with the slash removed.  
```js
JsMacros.on("SendMessage", JavaWrapper.methodToJava(function (event) {
  if (event.message === null) {
    return;  
  }
  if (event.message === "/hello") {
    // swallow it, nothing is sent and nothing is added to the history
    event.cancel();  
    return;  
  }
  // rewrite it, the client sends this instead of what was typed
  event.message = `say ${event.message}`;  
}))
```

## Constructors

### new EventSendMessage {#com.jsmacrosce.jsmacros.client.api.event.impl.EventSendMessage_constructor-String-}

```js
new EventSendMessage(String message)
```

Initializes the event with the supplied message; construction does not dispatch the event.

**Parameters:**
- `message`: initial message text, stored verbatim

## Fields

### message {#com.jsmacrosce.jsmacros.client.api.event.impl.EventSendMessage_message}

```js
message: String
```

The raw text submitted in the chat screen. A changed, nonempty value is sent without
normalization or history insertion; a leading `/` selects command submission, with the
slash removed. `null`, an empty string, or cancelling the event prevents sending.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.EventSendMessage_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the event name and current message text. The message
is not escaped, so this representation is not JSON.

**Returns:** event name and current message text in the form `%s:{"message": "%s"}`
