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

# Discord login

> Let customers sign in with Discord and receive roles in your server for their services.

![The OAuth app section of the Discord login settings](https://mintcdn.com/dezerx/5Dcc9_tGN8Ne6sDs/public/providers/discord/settings.webp?fit=max\&auto=format\&n=5Dcc9_tGN8Ne6sDs\&q=85\&s=39833a0a8ea18bed47a2d949b229cb36)

## Create the Discord app

**1. Create an application**

Open the [Discord developer portal](https://discord.com/developers/applications) and press New Application. Give it your store name.

**2. Add the redirect URL**

Go to OAuth2, press Add Redirect and paste the redirect URL from the Spartan settings page. It looks like this, with your own billing domain:

```text theme={null}
https://billing.example.com/auth/discord/callback
```

**3. Copy the client details**

On the OAuth2 page copy the Client ID, then reset and copy the Client Secret.

**4. Add a bot for roles and messages (optional)**

Open Bot, reset the token and copy it. Invite the bot to your server with the Manage Roles permission, and move its role above every role it should give out.

**5. Copy the server ID**

In Discord turn on Developer Mode, right click your server and choose Copy Server ID.

## Fill in Spartan

Open Admin, Integrations, Modules, Sign-in providers and press Settings on Discord. The Setup tab has three cards.

| Field | Value |
| - | - |
| Show on the login page | On by default. Turn it off to hide the button without removing the keys |
| Client ID | From OAuth2 |
| Client secret | From OAuth2. Once saved it is never shown again, leave the field blank to keep it |
| Redirect URL | Filled in with this site's callback URL. Press Copy and paste it into Discord. It must match exactly |
| Bot token | Optional. Needed for roles and direct messages |
| Server ID | Optional. Needed for roles |

Press Save settings. The Setup checklist on the right ticks off each step, and Details shows whether the button is shown, the credentials are complete and the redirect URL matches this site.

![The Bot section with the bot token and server ID](https://mintcdn.com/dezerx/5Dcc9_tGN8Ne6sDs/public/providers/discord/bot.webp?fit=max\&auto=format\&n=5Dcc9_tGN8Ne6sDs\&q=85\&s=1fc2f9eee98e1425d79e8b7d5937d948)

> [!NOTE]
>
> The Discord button only appears once a client ID and secret are saved, even if Show on the login page is on.

> [!NOTE]
>
> A customer is matched to an existing account by e-mail, but only if Discord has verified that e-mail. Otherwise they are asked to sign in with a password and link Discord from their profile.

## Role assignments

![Discord role sync events](https://mintcdn.com/dezerx/dVNBM3sq4VCh7CKa/public/providers/discord/top.webp?fit=max\&auto=format\&n=dVNBM3sq4VCh7CKa\&q=85\&s=92593f80fd58242a81269505836f3a9d)

Open the Role assignments tab. The bar at the top shows whether the bot is connected, to which server and how many roles it can see. Check connection asks Discord again and picks up renamed roles.

![Bot status on the Role assignments tab](https://mintcdn.com/dezerx/5Dcc9_tGN8Ne6sDs/public/providers/discord/roles.webp?fit=max\&auto=format\&n=5Dcc9_tGN8Ne6sDs\&q=85\&s=a72f5cb245ad24a92e5dc10911a45db3)

Press Add mapping, pick a role from your server and choose who gets it.

| Give it to customers with | Meaning |
| - | - |
| A product | An active or suspended service of that product |
| A category | An active or suspended service of any product in that category |
| Any service | Any active or suspended service |

![The Add role mapping dialog](https://mintcdn.com/dezerx/5Dcc9_tGN8Ne6sDs/public/providers/discord/mapping.webp?fit=max\&auto=format\&n=5Dcc9_tGN8Ne6sDs\&q=85\&s=69edafea841832dab4911d1b1105c5e4)

* Customers get the role when a service payment completes or when they link Discord. They lose it when the service is cancelled or terminated, unless another service still gives the same role.
* One role can be mapped to several products or categories.
* Pause a mapping to stop giving the role. Deleting a mapping leaves roles customers already have.
* Resync customers adds missing roles to every linked customer with an active service, in the background. It never removes roles.
* Until the bot is connected you can add a mapping by pasting a role ID.

The tab warns you when an active mapping points to a role that was deleted in Discord, and when a role sits above the bot's highest role, which Discord refuses to give. Drag the bot's role higher under Server settings, Roles.

Customers must link Discord first. With the bot token set, the bot also sends direct messages for payments, renewals, suspensions, terminations, upgrades and ticket replies.


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