# EventMiddleware

`class` in `seedcord` · v0.15.0

<https://docs.seedcord.org/packages/seedcord/0.15.0/classes/event-middleware>

Base class for Discord event middleware.

Middleware runs before event handlers and can stop the event by throwing a `Silence`. Unlike `EventHandler`, it runs the SAME for every event it is registered for, so it has no `match`. Specify a single event in the generic and `{ events }` to read `this.event` fully typed. Span several events (or omit `{ events }` for a catchall) and `this.event` narrows to `never`, read `this.eventName` and do work that does not depend on the payload shape. A middleware that needs each event's payload is written one event per class.

```ts
abstract class EventMiddleware<
    EventName extends ValidNonInteractionKeys = ValidNonInteractionKeys
>
    extends BaseHandler<ClientEvents[EventName]>
    implements Handler
```

## Constructors

### constructor

```ts
EventMiddleware(
    event: ClientEvents[EventName],
    core: Core,
    eventName?: EventName
)
```

Constructs a new instance of the `EventMiddleware` class

## Properties

### core

```ts
readonly core: Core
```

### event

```ts
protected readonly event: SingleEventPayload<EventName>
```

### eventName

```ts
protected eventName: EventName
```

The event that fired this middleware. Read it on a catchall or multi-event middleware, where `this.event` is `never`, to do work that does not depend on the payload shape. A single-event middleware reads `this.event` directly and does not need this.

### logger

```ts
protected readonly logger: Logger
```

## Methods

### execute

```ts
abstract async execute(): Promise<void>
```

Holds the main logic of your handler. The dispatcher calls it after the handler's gates pass, so a gate that refuses stops `execute()` from running.
