> For the complete documentation index, see [llms.txt](https://cjays-organization.gitbook.io/nexora.ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cjays-organization.gitbook.io/nexora.ts/framework/event-handler.md).

# EventHandler

Abstract base class for Discord.js client events. Same discovery as `event()` / `on()` / `onReady()` — export `default` from a file under `events/`.

**Package:** `@nexora.ts/core`

## Beginner (shortest path)

```ts
import { onReady } from '@nexora.ts/core';

export default onReady((client) => {
  console.log(`Logged in as ${client.user.tag}`);
});
```

```ts
import { on } from '@nexora.ts/core';

export default on('messageCreate', async (message) => {
  if (message.content === 'ping') await message.reply('pong');
});
```

## Class style

```ts
import { EventHandler } from '@nexora.ts/core';
import type { Client } from 'discord.js';

export default class ReadyHandler extends EventHandler<'ready'> {
  name = 'ready' as const;
  once = true;

  execute(client: Client) {
    client.user?.setActivity('Nexora', { type: 3 });
  }
}
```

## Typed event args

`name` is a Discord.js `ClientEvents` key. `execute` receives the matching argument list — full autocomplete in the IDE.

```ts
import { EventHandler } from '@nexora.ts/core';
import type { GuildMember } from 'discord.js';

export default class WelcomeHandler extends EventHandler<'guildMemberAdd'> {
  name = 'guildMemberAdd' as const;

  async execute(member: GuildMember) {
    const channel = member.guild.systemChannel;
    if (!channel) return;
    await channel.send(`Welcome, ${member}!`);
  }
}
```

## Fields

| Field        | Description                                             |
| ------------ | ------------------------------------------------------- |
| `name`       | Discord.js event name (`'ready'`, `'messageCreate'`, …) |
| `once`       | If `true`, listen with `client.once` (default: `false`) |
| `execute(…)` | Handler — args match `ClientEvents[name]`               |

## vs `event()` / `on()` / `onReady()`

```ts
// Still valid — same runtime
export default event('ready', (client) => {
  client.user?.setActivity('Nexora', { type: 3 });
}, true);
```

Prefer `onReady` / `on` for the shortest beginner path, `EventHandler` when you want typed args or shared base classes.

## Related

* [Events guide](/nexora.ts/commands-and-interactions/events.md)
* [SlashCommand](/nexora.ts/framework/slash-command.md)
* [Nexora](/nexora.ts/framework/nexora.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cjays-organization.gitbook.io/nexora.ts/framework/event-handler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
