> For the complete documentation index, see [llms.txt](https://docs.gamechat.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gamechat.me/basics/game-chat-v3/game-chat-english/start-using-v3/events.md).

# Events

## Events <a href="#undefined" id="undefined"></a>

Ncloud Chat provides the Event Listener function, which can handle diverse events that occur from the client side. With this function, you can monitor many circumstances occurring in the chat application in real time and respond to them properly. The following describes the main events and how to handle events.

## Main event types <a href="#undefined" id="undefined"></a>

1. **Receive message**: triggered when a new message is received.
2. **Delete message**: triggered when a message is deleted.
3. **Error message**: triggered when an error occurs.
4. **Connected**: triggered when successfully connected to the server.
5. **Disconnected**: triggered when disconnected from the server.
6. **Typing start and end**: triggered when you start or end typing.
7. **Add and remove members**: triggered when a user is added or removed.
8. **Member suspension and withdrawal**: triggered when a user gets suspended in the channel or withdraws from the channel.

The following shows how to listen for events on the client side.

```csharp
nc.dispatcher.onMessageReceived += message =>
{
    Console.WriteLine("received a new message: ", message);
}
```

## Connect and disconnect event handler <a href="#undefined" id="undefined"></a>

With event handlers, you can receive diverse events, and implement the logic you need. The following codes show how to connect and disconnect the event handler for each event.

```csharp
// Message Received
nc.dispatcher.onMessageReceived += e =>
{
    Console.WriteLine("onMessageReceived: ", e);
};

// Message Deleted
nc.dispatcher.onMessageDeleted += e =>
{
    Console.WriteLine("onMessageDeleted: ", e);
};

// Error Message
nc.dispatcher.onErrorReceived += e =>
{
    Console.WriteLine("[CloudChatSample] onErrorReceived: ", e);
};

// Connection Successful
nc.dispatcher.onConnected += e =>
{
    Console.WriteLine("[CloudChatSample] Connected to server with id: {0} ", e);
};

// Connection Closed
nc.dispatcher.onDisconnected += e =>
{
    Console.WriteLine("Disconnected");
};

// When Typing Starts
nc.dispatcher.onStartTyping += e =>
{
    Console.WriteLine("onStartTyping: ", e);
};

// When Typing Ends
nc.dispatcher.onStopTyping += e =>
{
    Console.WriteLine("onStopTyping: ", e);
};

// When a User Subscribes to the Channel
nc.dispatcher.onMemberAdded += e =>
{
    Console.WriteLine("onMemberAdded: ", e);
};

// When a User Unsubscribes from the Channel
nc.dispatcher.onMemberLeft += e =>
{
    Console.WriteLine("[CloudChatSample] onMemberLeft: ", e);
};

// When a User is Suspended from the Channel
nc.dispatcher.onMemberBanned += e =>
{
    Console.WriteLine("[CloudChatSample] onMemberBanned: ", e);
};

// When a User Leaves the Channel
nc.dispatcher.onMemberDeleted += e =>
{
    Console.WriteLine("[CloudChatSample] onMemberDeleted: ", e);
};

nc.dispatcher.onSubscriptionUpdated += e =>
{
    Console.WriteLine("[CloudChatSample] onSubscriptionUpdated: ", e);
};
```

With Event Listener, the user of Ncloud Chat can identify the change of the chat environment in real time and respond to it properly.


---

# 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://docs.gamechat.me/basics/game-chat-v3/game-chat-english/start-using-v3/events.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.
