> ## Documentation Index
> Fetch the complete documentation index at: https://developers.duelsplus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Client and chat

> Send messages, titles, and sounds to the player or server

# Client and chat

The `ctx.client` API lets you send messages and effects to the player's Minecraft client, or send messages to the server as if the player typed them.

## Sending chat to the player

Messages that appear in the player's chat (as if the server sent them):

```ts theme={null}
ctx.client.sendChat('§aHello!');
ctx.client.sendChat({ text: 'Hello!', color: 'green' }); // JSON style
```

Use `§` color codes for formatting (e.g. `§a` green, `§c` red, `§e` yellow, `§7` gray).

## Sending chat to the server (as the player)

Use this to type in chat or run commands as the player:

```ts theme={null}
ctx.client.sendGameChat('glhf');
ctx.client.sendGameChat('/play duels_uhc_duel');
```

* **sendChat(message)** - Message to the **player's client** (visible in their chat).
* **sendGameChat(message)** - Message to the **server** (Hypixel); appears as if the player typed it. Use for "glhf", "gg", or `/play ...` etc.

## Titles and action bar

```ts theme={null}
ctx.client.sendTitle('§a§lGAME START', `§7${payload.mode}`, {
  fadeIn: 5,
  stay: 40,
  fadeOut: 10,
});
ctx.client.sendActionBar('§eWinstreak: 5');
```

* **sendTitle(title, subtitle?, options?)** - Title and optional subtitle. `options`: `fadeIn`, `stay`, `fadeOut` (in ticks; default 10, 70, 20).
* **sendActionBar(message)** - Text above the hotbar (good for live stats).

## Sounds

```ts theme={null}
ctx.client.playSound('random.levelup', 0.5, 1.2);
ctx.client.playSound('mob.villager.death', 0.8, 0.8);
```

* **playSound(name, volume?, pitch?)** - Plays a sound for the player. `volume` 0–1 (default 1), `pitch` multiplier (default 1). Use Minecraft resource names (e.g. `random.levelup`, `mob.villager.death`, `note.harp`).

## When to use which

| Goal                                        | Method          |
| ------------------------------------------- | --------------- |
| Notify the player (visible in chat)         | `sendChat`      |
| Say something in game chat or run a command | `sendGameChat`  |
| Big announcement (title + subtitle)         | `sendTitle`     |
| Short live info (e.g. winstreak)            | `sendActionBar` |
| Feedback (victory, alert)                   | `playSound`     |

## Advanced

* **sendPacket(name, data)** - Send an arbitrary packet to the player's **client** (advanced).
* **sendServerPacket(name, data)** - Send an arbitrary packet to the **server** (advanced).
* **disconnect(reason?)** - Disconnect the player from the proxy.

All of these no-op or fail gracefully if no player is connected (`ctx.client.isConnected` is false). You can read `ctx.client.username` and `ctx.client.uuid` when connected.
