> ## 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.

# Invite

> Read the link, the uses and the expiry of an invite, and delete it

An `Invite` is an invite to a server. You get one from `channel.createInvite()`, `channel.fetchInvites()` or `guild.fetchInvites()`.

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

async function invite(channel: TextChannel) {
  const invite = await channel.createInvite({ maxAge: 3600, maxUses: 1, unique: true });
  return invite.url; // https://discord.gg/...
}
```

> [!NOTE]
>
> What `createInvite()` takes is in [InviteCreateOptions](https://www.chapterjs.org/reference/options.md#invitecreateoptions). Which channels can create one is in [Channels](https://www.chapterjs.org/reference/channels).

## Properties

**inviter** `User | null`

Who created the invite, when Discord says it.

**code** `string`

The unique code of the invite (`discord.gg/code`).

**url** `string`

The link to share.

**guildId** `Snowflake | null`

The id of the server the invite leads to.

**channelId** `Snowflake | null`

The id of the channel the invite leads to.

**channel** `GuildChannel | null`

The channel the invite leads to, when the bot knows it. It never sends a request.

**expiresAt** `Date | null`

When the invite stops working; `null` when it never does.

**uses** `number | null`

How many times the invite was used, when Discord says it.

**maxUses** `number | null`

How many times the invite can be used; `0` means no limit.

**temporary** `boolean`

Whether members who joined with it are kicked when they go offline.

> [!NOTE]
>
> An invite has no `id` and no `createdAt`: Discord identifies it by its `code`.

## Helpers

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

### toString()

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

The link to share.

### toJSON()

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

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

## Actions

### delete()

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
delete(reason?: string): Promise<void>
```

Deletes the invite: its link stops working.

[Discord documentation](https://docs.discord.com/developers/resources/invite#delete-invite)

## Types

`InviteCreateOptions` is in [Options](https://www.chapterjs.org/reference/options.md#invitecreateoptions).


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