# Embeds and attachments

> Rich embeds built with EmbedBuilder, and files sent as encrypted attachments.

## Embeds

Embeds have a title, description, link, colour, timestamp, author, footer, up to
25 fields, an image and a thumbnail. Up to 10 per message.

**JavaScript:**

```js

const embed = new EmbedBuilder()
  .setTitle("Release 1.2")
  .setURL("https://example.com/releases/1.2")
  .setDescription("What changed")
  .setColor(0x5865f2)
  .addFields({ name: "Fixes", value: "12", inline: true }, { name: "Features", value: "3", inline: true })
  .setImage({ name: "screenshot.png", data: bytes })
  .setFooter({ text: "zaun" });
await channel.send({ embeds: [embed] });
```

**Rust:**

```rust
use zaun_client::{EmbedBuilder, MessageOptions, Picture};

let embed = EmbedBuilder::new()
    .title("Release 1.2")
    .url("https://example.com/releases/1.2")
    .description("What changed")
    .color(0x5865F2)
    .field("Fixes", "12", true)
    .field("Features", "3", true)
    .image(Picture::file("screenshot.png"))
    .footer("zaun", None);
channel.send(MessageOptions::new().embed(embed))?;
```

> **Caution: Pictures are files, never URLs**
>
> An embed's image, thumbnail and icons are **attachments of the same message**: the client uploads
> them with the message. No reader's app ever fetches an image from a third party, which would show
> that server the reader's IP address. Links (`url`) must be `https://` and open only when clicked.
## Attachments

**JavaScript:**

```js
await channel.send({ content: "my cat", files: [{ name: "cat.png", data: bytes }] });

// on the other side
const bytes = await message.attachments.first().download();
```

**Rust:**

```rust
channel.send_files("my cat", &["cat.png"])?;

// on the other side, from an Event::MessageCreate
let saved = message.attachments()[0].download("./downloads")?;
```

Files travel as SimpleX files over the same post-quantum connection, each encrypted with a fresh
key. Sending returns once the host has checked and stored the files; downloading checks the size and
SHA3-256 before anything is saved. The host's `[attachments]` settings cap the size (25 MB by
default). With your own SMP relay, add an XFTP relay too, or there is no file server.
