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

# Discord User Provisioning & Deprovisioning

> Automate Discord user provisioning and deprovisioning from your HRIS. Klef creates, updates, and deactivates accounts when HR makes a change.

![](https://mintcdn.com/klef/O1Sswmcb_uCGkmIf/images/connectors/discord.svg?fit=max\&auto=format\&n=O1Sswmcb_uCGkmIf\&q=85\&s=32aac43a05e25ca8b9eafe9eaaca4820)

# Discord

## Connection

### Setup

Klef manages your Discord server through a bot you add to it.

**Step 1**

In the [Discord Developer Portal](https://discord.com/developers/applications), choose **New Application**. Under **Bot**, turn on **Server Members Intent**, then choose **Reset Token** and copy the token.

**Step 2**

Under **OAuth2**, then **URL Generator**, choose the `bot` scope and the **Manage Roles**, **Kick Members**, and **Manage Nicknames** permissions. Open the URL it makes and add the bot to your server.

**Step 3**

In your server's **Settings**, under **Roles**, drag the bot's role above every role Klef should assign.

**Step 4**

In Discord, turn on **Developer Mode** under **Settings**, then **Advanced**. Right-click your server, choose **Copy Server ID**, and copy it into Klef with the bot token.

A bot cannot add anyone to a server, so each person joins with an invite before Klef manages them. Klef matches them by their Discord username, so keep each worker's username in an HR custom field, such as `discord_username`.

Klef keeps each member's nickname and roles. It offers only the roles below the bot's own that no integration manages. Switching a member off kicks them from the server.

### Settings

| Setting | Required | Description |
| - | - | - |
| Server ID | Yes | ID of your Discord server. Turn on Developer Mode, then right-click the server and copy its ID. |
| Bot token | Yes | Token of the bot you added to the server for this connection. |

## discord.member

### Fields

| Field | Type | Required | Description |
| - | - | - | - |
| `username` | string | Yes | Discord username of someone already in the server. The connector does not change it. Never changed once the account exists. |
| `nickname` | string | | Nickname in this server. |
| `roles` | entitlements | | Roles the member holds. The connector offers the roles below the bot's own that no integration manages. One row grants one role. |
| `roles[]` | string | | Role ID. |
| `status` | enum | | Whether the person can sign in, the account is kept switched off, or the account is gone. Values: `removed` (Removed). |

### Default Account Matching Rules

When Klef [adopts](https://klef.ai/docs/adoption.md) an account that already exists in Discord, it works out whose it is by trying these in order. A connection can override them.

| Account field | Worker field |
| - | - |
| `username` | `worker.custom_fields.discord_username` |

## Examples

### Discord members

Keeps each engineer's Discord nickname set, and kicks them from the server when they leave.

```hcl theme={null}
stage active {
  target discord.member {
    username = worker.custom_fields.discord_username
    nickname = worker.display_name
  }
}
```


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