# installation

## Prerequisites

* FiveM Server
* MySQL Database (oxmysql)
* Node.js installed on server
* Discord Bot Token
* screenshot-basic resource

## Dependencies

Add to your `server.cfg`:

```cfg
ensure oxmysql
ensure screenshot-basic
ensure sl-bot
```

{% stepper %}
{% step %}

### Install Resource

* Download and extract `sl-bot` to your resources folder
* Place in `resources/[sl]/sl-bot` or your preferred location
  {% endstep %}

{% step %}

### Install Node.js Dependencies ( Optional if the server does not install it itself )&#x20;

Navigate to the resource folder and install dependencies:

```bash
cd resources/[sl]/sl-bot
npm install
```

{% endstep %}

{% step %}

### Create Discord Bot

1. Go to <https://discord.com/developers/applications>
2. Click "New Application" and give it a name
3. Go to "Bot" section and click "Add Bot"
4. Enable these Privileged Gateway Intents:
   * ✅ PRESENCE INTENT
   * ✅ SERVER MEMBERS INTENT
   * ✅ MESSAGE CONTENT INTENT
5. Copy your Bot Token
6. Go to OAuth2 → URL Generator:
   * Scopes: `bot`
   * Bot Permissions: `Administrator`
7. Copy the generated URL and invite bot to your server
   {% endstep %}

{% step %}

### Configure .env File

Create a `.env` file in the resource folder with the following content:

```env
# Discord Bot Token (from Developer Portal)
TOKEN=YOUR_BOT_TOKEN_HERE

# Owner Role ID (full access to all commands)
OWNER_ROLE_ID=123456789012345678

# Admin Role ID (fallback for commands without specific roles)
ADMIN_ROLE_ID=123456789012345678

# Log Channel ID (optional)
LOG_CHANNEL_ID=123456789012345678

# Command Prefix (default: !)
PREFIX=!
```

How to get Role/Channel IDs:

1. Enable Developer Mode in Discord (Settings → App Settings → Advanced → Developer Mode)
2. Right-click on a role or channel
3. Click "Copy ID"
   {% endstep %}

{% step %}

### Configure Permissions

Edit `shared/config.lua` to set command permissions:

```lua
Config.CommandPermissions = {
    ['ban'] = { roles = { '123456789012345678' } },
    ['kick'] = { roles = { '123456789012345678', '987654321098765432' } },
    -- Add more...
}
```

Note: Empty `roles = {}` uses `ADMIN_ROLE_ID` from .env as fallback. Users with `OWNER_ROLE_ID` always have access to all commands.
{% endstep %}

{% step %}

### Configure Webhooks

Edit `editable/logs.lua` to set webhook URLs:

```lua
LogsConfig.ScreenshotWebhook = 'https://discord.com/api/webhooks/...'

LogsConfig.Commands = {
    ban = { enabled = true, webhook = 'https://discord.com/api/webhooks/...', color = 0xFF0000, title = 'Player Banned' },
    -- Configure other commands...
}
```

{% endstep %}

{% step %}

### Start Server

The script will automatically create database tables on first start:

* `sl_bans` - Ban records
* `sl_warnings` - Warning records
  {% endstep %}
  {% endstepper %}

{% hint style="success" %}
After starting the server, check console for:

```
[SL-Bot] Bot ready: YourBot#1234
```

If you see this message, the bot is connected and ready!
{% endhint %}

## ❌ Common Issues (FAQ)

<details>

<summary>Bot won't connect</summary>

* Check if TOKEN in `.env` is correct
* Verify Node.js dependencies are installed (`npm install`)
* Check console for error messages

</details>

<details>

<summary>Commands not working</summary>

* Verify your Discord role is in the permission list
* Check if you're using correct prefix (default: `!`)
* Ensure bot has proper permissions in Discord

</details>

<details>

<summary>Database errors</summary>

* Make sure `oxmysql` is started before `sl-bot`
* Check MySQL connection settings

</details>
