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

# User

> Read a Discord account, get its avatar and send it a private message

A `User` is a Discord account, the same in every server. You get one as the `user` of a [command](https://www.chapterjs.org/reference/interaction.md), as `message.author`, as `member.user` and as the `user` of the `memberLeave` [event](https://www.chapterjs.org/reference/events.md). For what is specific to one server (nickname, roles, permissions), see [GuildMember](https://www.chapterjs.org/reference/member.md).

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import type { User } from 'chapterjs';

async function greet(user: User) {
  if (user.bot) return;
  await user.send({
    content: `Hi ${user.displayName}!`,
    embeds: [{ thumbnail: { url: user.avatarURL({ size: 256 }) } }],
  });
}
```

> [!NOTE]
>
> How your functions receive a user is in [Commands](https://www.chapterjs.org/commands.md) and [Events](https://www.chapterjs.org/events.md). What a private message can hold is in [Messages](https://www.chapterjs.org/messages.md).

> [!WARNING]
>
> Sending a private message fails when the user has closed their private messages or shares no server with the bot. Catch the error when that is fine for you: see [Errors](https://www.chapterjs.org/reference/errors.md).

## Properties

**id** `Snowflake`

The unique id Discord gave it.

**createdAt** `Date`

When it was created: a Discord id contains its creation date.

**username** `string`

The unique name of the account (`@name`).

**globalName** `string | null`

The name shown in Discord, when the user chose one.

**displayName** `string`

The name to show: the display name, or else the username.

**discriminator** `string`

`"0"` for users on the current username system.

**bot** `boolean`

Whether the account is a bot.

**system** `boolean`

Whether the account is an official Discord system account.

**avatar** `string | null`

The hash of the avatar; use `avatarURL()` to get the image.

**banner** `string | null`

The hash of the banner; use `bannerURL()` to get the image.

**accentColor** `number | null`

The banner color, as a number (`0xff0000`).

**locale** `Locale | null`

Only known for the bot itself. See [Locale](https://www.chapterjs.org/reference/enums.md#locale).

**flags** `UserFlagName[]`

The public badges of the account, by name. See [UserFlagName](#userflagname).

## Helpers

These read what the bot remembers: they never send a request.

### avatarURL()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
avatarURL(options?: ImageOptions): string
```

The URL of the avatar; of the default one when none is set. See [ImageOptions](https://www.chapterjs.org/reference/helpers.md#imageoptions).

### bannerURL()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
bannerURL(options?: ImageOptions): string | null
```

The URL of the banner, when one is set. See [ImageOptions](https://www.chapterjs.org/reference/helpers.md#imageoptions).

### toString()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
toString(): string
```

`<@id>`: mentions the user when put in a message.

### toJSON()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
toJSON(): object
```

The data of Discord as a plain object, with camelCase names.

## Reading from Discord

### fetch()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
fetch(): Promise<User>
```

Asks Discord for the latest data of this user.

## Actions

### createDM()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
createDM(): Promise<DMChannel>
```

Opens the private conversation with this user. See [DMChannel](https://www.chapterjs.org/reference/channels/dm.md).

[Discord documentation](https://docs.discord.com/developers/resources/user#create-dm)

### send()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
send(message: MessageInput): Promise<Message>
```

Sends a private message to this user. See [MessageInput](https://www.chapterjs.org/reference/message-options.md#messageinput).

## Types

### UserFlagName

The name of a public badge, as `flags` lists them: one of the keys of [`UserFlags`](https://www.chapterjs.org/reference/enums#userflags).

| Name | Badge |
| - | - |
| `Staff` | Discord Employee |
| `Partner` | Partnered Server Owner |
| `Hypesquad` | HypeSquad Events Member |
| `BugHunterLevel1` | Bug Hunter Level 1 |
| `HypesquadOnlineHouse1` | House Bravery Member |
| `HypesquadOnlineHouse2` | House Brilliance Member |
| `HypesquadOnlineHouse3` | House Balance Member |
| `PremiumEarlySupporter` | Early Nitro Supporter |
| `TeamPseudoUser` | User is a team |
| `BugHunterLevel2` | Bug Hunter Level 2 |
| `VerifiedBot` | Verified Bot |
| `VerifiedDeveloper` | Early Verified Bot Developer |
| `CertifiedModerator` | Moderator Programs Alumni |
| `BotHttpInteractions` | Bot uses only HTTP interactions and is shown in the online member list |

[Discord documentation](https://docs.discord.com/developers/resources/user#user-object-user-flags)

`ImageOptions` is in [Helpers](https://www.chapterjs.org/reference/helpers.md#imageoptions).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.