# Events

Time to go over the events that are available for you to subscribe to, as well as all the data that each event emits.

## Available Events

This is the \*current\* list of available events, as time goes on more events may be added, but to keep overlays that have been made working, event types will never be removed unless absolutely necessary.

* `message`
* `command`
* `sticker`
* `support`
* `follow`
* `subscription`
* `giftsub`
* `resub`
* `host`
* `raid`

## Event Data

Each event has different data that it will emit when the event happens, so let's go over those!

### Message

The message event is likely the event that will be most commonly used. It is also the event that has the most "pre-processing" done to it. First, we'll just show you what it looks like, then we'll give a brief overview of how it's structured.

```typescript
interface IMessageEmote {
  type: "emote";
  url: string;
  text: string;
}

interface IMessageText {
  type: "text";
  text: string;
}

type IMessage = IMessageEmote | IMessageText;

interface IChatMessage {
  user: {
    displayName?: string;
    name: string;
    id: string;
    color: string;
    badges?: string[];
    avatar: string;
    isMod: boolean;
    isSub: boolean;
  };
  special?: string;
  message: IMessage[];
  id: string;
  from: string;
}
```

This is the message event, it is the `IChatMessage` that will be emitted to your listener. Most of this event should be pretty obvious, the slightly unconventional part is the way the actual chat message is formatted. Within the event, there is an array property called `message` this property is an array that contains n elements that are *either* a text message, or an emote message. This is done like this because Pixel Chat parses out all emotes for you! The other small thing to note is the `from` property, this property specifies what platform the message is from, be that `twitch` of `trovo` etc.

### Command

```typescript
interface ICommand {
  command: string;
  user: {
    displayName?: string;
    name: string;
    id: string;
    color: string;
    badges?: string[];
    avatar: string;
    isMod: boolean;
    isSub: boolean;
  };
  args: string[];
  from: string;
}
```

This is the command event, it is emitted every time there is a message event and is designed to make dealing with commands a little bit easier. The `command` property will always be the first word in the message, and the `args` array will be everything that comes after that, split by spaces.

### Sticker

```typescript
interface ISticker {
  user: {
    name: string;
    avatar: string;
  };
  sticker: {
    url: string;
    name: string;
    currency: string;
    price: number;
    bg: {
      initial: string | null;
      loop: string | null;
    };
  };
}
```

The sticker event is an event exclusive to Trovo, and emits whenever a sticker is used in chat. the event will contain info such as the url to the gif of the sticker, as well as the urls for the background animations assuming they exist for the said sticker.

### Support

```typescript
interface ISupport {
  username: string;
  avatar: string;
  amount: number | string;
  message?: string;
  currency: string;
}
```

This is going to be your basic support events, such as bits, mana, or elixir. The "currency" field represents what currency was used and as of writing this will always be one of `[bits, mana, elixir].`

### Follow

```typescript
interface IFollow {
  user: {
    name: string;
    avatar: string;
  };
}
```

This is your basic follow event, it will be fired whenever a viewer follows the channel.

### Subscription

```typescript
interface ISubscription {
  user: {
    name: string;
    avatar: string;
  };
  level?: number;
}
```

### GiftSub

```typescript
interface IGiftSub {
  user: {
    name: string;
    avatar: string;
  };
  recipient: {
    name: string;
    avatar: string;
  };
  level?: number;
}
```

### Resub

```typescript
interface IResubscription {
  user: {
    name: string;
    avatar: string;
  };
  months: number;
  message?: string;
}
```

### Host

```typescript
interface IHost {
  user: {
    name: string;
    avatar: string;
  };
  viewers?: number;
}
```

Please note that host events are not emitted for Twitch channels, as these events are not easily available from twitch.

### Raid

```typescript
interface IRaid {
  user: {
    name: string;
    avatar: string;
  };
  viewers?: number;
}
```


---

# Agent Instructions: 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:

```
GET https://docs.pixel.chat/api-docs/overlays/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
