> For the complete documentation index, see [llms.txt](https://scripting.breeze.rip/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scripting.breeze.rip/newgen/event_listeners.md).

# Event Listeners

Use `script.addListener` to react to game events. All listeners must be registered during script initialization.

#### Basic Usage

```js
script.addListener("EventName", (event) => {
    // handle event
});
```

#### Several listeners and priority

You can add as many listeners for the same event as you like. Pass a priority as the third argument to decide the order: higher priorities run first, and the default is 0. The same numbers order your listeners against Breeze's own modules.

```js
script.addListener("PreTickEvent", () => {
    // runs first
}, 10);

script.addListener("PreTickEvent", () => {
    // runs after the one above
});
```

#### Cancelling

Events like [PacketSendEvent](/newgen/api/events/packetsendevent.md) and [KeyPressedEvent](/newgen/api/events/keypressedevent.md) can be cancelled.

```js
script.addListener("PacketSendEvent", (event) => {
    if (event.packet instanceof ServerboundSwingPacket) {
        event.cancel(); // the server never sees the swing
    }
});
```

{% content-ref url="<https://github.com/LoseBypass/breeze-newgen-docs/tree/master/docs/api/Events/README.md>" %}
<https://github.com/LoseBypass/breeze-newgen-docs/tree/master/docs/api/Events/README.md>
{% endcontent-ref %}
