# Installation

Add the resource, database table and server.cfg entry.

## 1. Add the resource

Place the `wd_richpresence` folder in your server's `resources` directory. **Do not rename it**; exports and events use the folder name.

## 2. Turn off other Rich Presence scripts

A player can only show one Discord Rich Presence. If another resource also sets it, the two overwrite each other: the profile keeps switching between them, and the character photo may never appear. Turn off every other presence before continuing.

### Qbox

Qbox has its own Discord presence, and it is **on by default**.

1. Open `qbx_core/config/client.lua`.
2. Find the `discord = {` section.
3. Change `enabled = true` to `enabled = false`:

```lua qbx_core/config/client.lua
discord = {
    enabled = false, -- This will enable or disable the built in discord rich presence.
```

4. Save the file.

### QBCore

`qb-smallresources` includes a Discord presence. It is off by default, but check it in case it was turned on.

1. Open `qb-smallresources/config.lua`.
2. Find the `Config.Discord = {` section.
3. Make sure it says `isEnabled = false`:

```lua qb-smallresources/config.lua
Config.Discord = {
    isEnabled = false, -- If set to true, then discord rich presence will be enabled
```

4. Save the file.

### ESX

ESX Legacy includes a Discord presence. It is off while its Application ID is `0`, which is the default.

1. Open `es_extended/shared/config/adjustments.lua`.
2. Find the `Config.DiscordActivity = {` section.
3. Make sure it says `appId = 0`:

```lua es_extended/shared/config/adjustments.lua
Config.DiscordActivity = {
    appId = 0, -- Discord Application ID,
```

4. Save the file.

### Find any other presence scripts

Other resources can set a presence too. To find them, search your `resources` folder for `SetDiscordAppId`, which every presence script uses.

On Windows, open Command Prompt in your `resources` folder and run:

```bash Windows
findstr /s /i /m "SetDiscordAppId" *.lua
```

On Linux, run this in your `resources` folder:

```bash Linux
grep -ril "SetDiscordAppId" --include=*.lua .
```

Every file listed, other than those in `wd_richpresence` and the ones turned off above, belongs to another presence script. Turn off its presence option, or remove the resource from `server.cfg` if presence is all it does. Escrowed resources cannot be searched this way, so also check the configs of paid scripts for a Discord or Rich Presence option.

These changes take effect after a server restart, which you will do in the last step.

## 3. Create the database table

The resource creates its table automatically the first time it starts, so you can skip this step. If you prefer to create it yourself, import the included [`wd_richpresence.sql`](reference/wd_richpresence/wd_richpresence.sql) into the database used by oxmysql:

```sql wd_richpresence.sql
CREATE TABLE IF NOT EXISTS `wd_richpresence_mugshots` (
    `identifier` VARCHAR(100) NOT NULL,
    `url` VARCHAR(1024) NOT NULL,
    `appearance_hash` VARCHAR(64) NOT NULL,
    `host` VARCHAR(16) NOT NULL DEFAULT 'fivemanage',
    `remote_id` VARCHAR(64) DEFAULT NULL,
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

To turn off automatic table creation, set `ServerConfig.AutoCreateTable = false` in `server_config.lua`.

## 4. Add it to server.cfg

Start Wolfden Rich Presence **after** oxmysql, your framework and your clothing script:

```cfg server.cfg
ensure oxmysql
ensure qbx_core        # or qb-core / es_extended
ensure illenium-appearance
ensure wd_richpresence
```

If your framework starts later than this resource, it is not detected and the resource falls back to standalone mode.

## 5. Set up Discord

Follow [Discord application](#/docs/wd_richpresence/discord-app) to get your Application ID, upload your logo and add your buttons. Without an Application ID, no presence is shown.

## 6. Connect an image host

Follow [Image hosting](#/docs/wd_richpresence/image-hosting) to store character photos on Fivemanage, or on your own server.

## 7. Restart and test

1. Restart your server.
2. Check the server console. You should see `Framework: qbox` (or your framework) and no `Mugshots disabled` warning.
3. Join with the Discord desktop app running. Your profile shows your logo and the character selection messages.
4. Load a character. After about five seconds, the large image changes to your character's face.
5. Stay in the city for two minutes. The presence should keep showing your application name and messages. If it switches to another name or image, another presence is still on; go back to [step 2](#2-turn-off-other-rich-presence-scripts).

Your own **Join Server** and **Discord** buttons are hidden from you by Discord. Ask a friend, or use a second account, to check them.

If something does not appear, set `Config.Debug = true` and see [Troubleshooting](#/docs/wd_richpresence/troubleshooting).
