> For the complete documentation index, see [llms.txt](https://docs.ragnasync.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ragnasync.com/ragnascript/discord-auth.md).

# Discord Authentication

Link player accounts to Discord users for enhanced features

The `discord_auth` script allows players to link their Ragnarok Online accounts to their Discord accounts. Once linked, their in-game messages can show their Discord identity and unlock future Discord-integrated features.

## How It Works

1. **Get your code**: Use the `/authentication_code` slash command in Discord
2. **Enter in-game**: Talk to an NPC and enter your 8-digit code
3. **Done!**: Your accounts are now linked

## Discord Command

Players use the `/authentication_code` slash command in your Discord server to get their unique authentication code.

The command returns a **private message** (only visible to the user) containing their 8-digit code:

```
Your code: 12345678

Enter this code in-game to link your Ragnarok account to your Discord account.
```

Each Discord user gets a unique code that doesn't change, so they can use it again if needed.

## NPC Script Example

Here's a simple NPC that handles Discord authentication:

```c
prontera,150,180,4	script	Discord Link	4_M_SAGE_B,{
    mes "[Discord Link]";
    mes "Would you like to link your Discord account?";
    mes "Use ^0055FF/authentication_code^000000 in Discord to get your code.";
    next;

    input .@code$;

    if (.@code$ == "") {
        mes "[Discord Link]";
        mes "No code entered. Come back when you have your code!";
        close;
    }

    // Send the authentication request to RagnaSync
    ragnascript "[action: discord_auth][name: " + strcharinfo(PC_NAME) + "][code: " + .@code$ + "][account_id: " + getcharid(CHAR_ID_ACCOUNT) + "][char_id: " + getcharid(CHAR_ID_CHAR) + "]";

    mes "[Discord Link]";
    mes "Checking your code...";
    mes "You'll receive a whisper with the result!";
    close;
}
```

## Data Fields

| Field        | Type   | Required | Description                                  |
| ------------ | ------ | -------- | -------------------------------------------- |
| `name`       | string | Yes      | Character name (for whisper response)        |
| `code`       | string | Yes      | The 8-digit authentication code from Discord |
| `account_id` | int    | Yes      | Player's account ID                          |
| `char_id`    | int    | Yes      | Character ID                                 |

## Response Messages

After processing, RagnaSync sends a whisper to the player:

**Success:**

> Successfully linked your character to Discord user YourDiscordName!

**Invalid Code:**

> Authentication failed. Invalid code: 12345678

## Notes

* Each Discord user has a unique, persistent authentication code
* The code is shown only to the Discord user (ephemeral message)
* Players can re-link at any time using the same code
* Authentication links the player's game account to their Discord identity
* Future features can leverage this linkage for enhanced Discord integration
