# listen

*LSL event*

```lsl
listen(integer channel, string name, key id, string msg)
```

- `integer channel`: Chat channel where the message appeared.
- `string name`: Name of the sending prim or the legacy name of the sending agent.
- `key id`: UUID of the sending agent or prim.
- `string msg`: Spoken text string.

Triggered when a chat message matching active llListen filters is received on channel. Passes the sender's name and UUID key id, along with the spoken string msg.

Triggered by chat, use [llListen](/functions/llListen/) to enable and filter

```lsl title="How to use" frame="terminal"
listen(integer channel, string name, key id, string msg)
{

}
```

## Specification

<table>
	<tr>
		<th colspan="2">Channel Constant</th>
		<th>Description</th>
	</tr>
	<tr>
		<td>[DEBUG_CHANNEL](/constants/DEBUG_CHANNEL/)</td>
		<td>0x7FFFFFFF</td>
		<td>Chat channel reserved for script debugging and error messages, broadcasts to all nearby users.</td>
	</tr>
	<tr>
		<td>[PUBLIC_CHANNEL](/constants/PUBLIC_CHANNEL/)</td>
		<td>0x0</td>
		<td>Chat channel that broadcasts to all nearby users. This channel is sometimes referred to as: open chat, local chat and public chat.</td>
	</tr>
</table>

## Caveats

- On [state](https://wiki.secondlife.com/wiki/state) change or [script reset](/functions/llResetScript/) all listens are [closed](/functions/llListenRemove/) automatically.
- When an object changes owner any listen registered with [llGetOwner](/functions/llGetOwner/) will not automatically update itself until the script is reset. The scripter can catch this scenario per the example below.
- If a message satisfies the filters of multiple [llListen](/functions/llListen/)s registered by the script, only one event will be raised.
- A prim cannot hear/listen to chat it generates.
- The location of the listen is not at the listening prim's location but at the root prim's location. This is to deter people using child prims for spying over parcel boundaries. [Chat generating functions](/categories/chat/) on the other hand generate chat at the calling prim's location (and not at the root prim's location).
- The above is not true for chat generated by avatars sitting on the same object as the listening prim.

## Examples

<details open>
<summary>Example 1</summary>

:::note
Please make sure that you close open listeners where possible. You'll make the Second Life experience so much better when paying attention to details here.
:::

Trivial example to listen to any chat from the object owner and respond once. To reduce lag and avoid spamming surrounding users, it is vastly preferable to listen on channels other than 0 and to trigger the listen event by chatting on an alternative channel such as '/5 hello'.

```lsl collapse={20-26}
// says beep to owner the first time owner says something in main chat;
integer listen_handle;

default
{
    state_entry()
    {   //Registers the listen to the owner of the object at the moment of the call. This does not automatically update when the owner changes.
        // Change 0 to another positive number to listen for '/5 hello' style of chat.
        listen_handle = llListen(0, "", llGetOwner(), "");
    }

    listen( integer channel, string name, key id, string message )
    {
        llOwnerSay("beep");
        // Stop listening until script is reset
        llListenRemove(listen_handle);
    }

    changed(integer mask)
    {   //Triggered when the object containing this script changes owner.
        if(mask & CHANGED_OWNER)
        {
            llResetScript();   // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.
        }
    }
}
```

</details>

## Known issues

From the issue templates included by the wiki article:

- SVC-92 (nf): **llTargetSay**() - region-wide direct communication

## See also

### Functions

- [llListen](/functions/llListen/)
- [llListenControl](/functions/llListenControl/)
- [llListenRemove](/functions/llListenRemove/)
- [llDialog](/functions/llDialog/)
- [llOwnerSay](/functions/llOwnerSay/) — Sends chat to the owner only to avoid spamming the [PUBLIC_CHANNEL](/constants/PUBLIC_CHANNEL/)
- [llWhisper](/functions/llWhisper/) — Sends chat limited to 10 meters
- [llSay](/functions/llSay/) — Sends chat limited to 20 meters
- [llShout](/functions/llShout/) — Sends chat limited to 100 meters
- [llRegionSay](/functions/llRegionSay/) — Sends chat limited to region

---

*Source: [Listen](https://wiki.secondlife.com/wiki/Listen) on the Second Life Wiki. Content from the Second Life Wiki articles Listen (revision 1213353, 2023-02-09), PUBLIC CHANNEL (revision 1217155, 2024-08-15), DEBUG CHANNEL (revision 1217156, 2024-08-15), Template:LSL Constants/Chat (revision 1141644, 2011-04-25), Template:LSL Function/uuid (revision 1195911, 2015-03-21) and Template:Issues/SVC-92 (revision 1142929, 2011-05-09), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/events/listen/
