> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-adminbot/cas-adminbot.md).

# CAS AdminBot

**CAS AdminBot** is a standalone Discord bot for **RedM** server administration. It runs directly inside your RedM server (no external hosting) and provides moderation, whitelisting and utilities through Discord slash commands. Its modular architecture makes it easy to extend with custom commands, events and addons.

## Highlights

* **Standalone** — runs in RedM, no external hosting
* **Slash commands** with autocomplete and per-command permission levels
* **Moderation** — kick, ban, message, kill, announce
* **Whitelist** — role-based Discord whitelist enforcement
* **Staff chat** — two-way Discord ⇄ in-game staff messaging
* **Auto ACE permissions** — grant server groups from Discord roles
* **VorpCore integration** — currency, inventory, jobs, permissions, heal/revive
* **Webhook logging** and dynamic bot status messages
* **Modular** — add commands/events/addons as drop-in files

## At a glance

|               |                                           |
| ------------- | ----------------------------------------- |
| Platform      | RedM (artifacts build 16565+ recommended) |
| Runtime       | Node.js bundled with RedM (via `yarn`)    |
| Optional      | VorpCore (for VORP commands)              |
| Resource name | `cas_adminbot`                            |
| Config        | `config.js` (or `server.cfg` convars)     |

## Permission levels

`user` (all members) · `mod` · `admin` · `founder` (owner). Each command declares the minimum role it needs.

## Requirements

* RedM artifacts build 4890+ (16565+ recommended)
* `cfx-server-data` present (`yarn` at minimum) in your resources
* A Discord bot application + token, in a guild you manage
* **Both privileged intents enabled**: Server Members Intent, Message Content Intent
* Optional: VorpCore for VORP-specific commands

## Installation

### 1. Create the Discord bot

[Discord Developer Portal](https://discord.com/developers/applications) → New Application → Bot → enable **Server Members Intent** and **Message Content Intent** → copy the token.

### 2. Invite it

```
https://discord.com/api/oauth2/authorize?client_id=YOUR-BOT-ID&permissions=8&scope=bot%20applications.commands
```

Re-run this if the bot is already in the server but missing the `applications.commands` scope.

### 3. Install the resource

Place `cas_adminbot` in your resources (folder named exactly `cas_adminbot`). Verify `[system]/[builders]/yarn/` exists.

### 4. server.cfg

```cfg
ensure yarn
ensure vorp_core     # if using VorpCore, load it before the bot
ensure cas_adminbot
```

### 5. Configure & start

Edit `config.js` (minimum: token, guild ID, server name), start the server and watch for:

```
[cas_adminbot][TIMESTAMP][INF]: Bot is ready!
```

## Configuration

All settings live in `config.js` (or override via `server.cfg` convars).

### General

```javascript
const LanguageLocaleCode = "en";
const RedMServerName = "Your Server Name";
const DiscordInviteLink = "https://discord.gg/yourcode";
const RedMServerIP = "127.0.0.1";
const DebugLogs = false;
```

### Discord bot

```javascript
const EnableDiscordBot = true;
const DiscordBotToken = "YOUR_BOT_TOKEN";
const DiscordGuildId = "YOUR_GUILD_ID";
```

### Staff chat

```javascript
const EnableStaffChatForwarding = true;
const DiscordStaffChannelId = "CHANNEL_ID_HERE";
const AdditionalStaffChatRoleIds = ["ROLE_ID_1", "ROLE_ID_2"];
```

Staff use `/staff <message>` in-game; messages in the staff channel are forwarded to in-game staff.

### Whitelist

```javascript
const EnableWhitelistChecking = true;
const DiscordWhitelistRoleIds = "ROLE_ID_1, ROLE_ID_2";
```

Players must have Discord open and one of these roles to join.

### Command roles

```javascript
const EnableDiscordSlashCommands = true;
const DiscordModRoleId = "ROLE_ID";
const DiscordAdminRoleId = "ROLE_ID";
const DiscordFounderRoleId = "ROLE_ID";
```

### Bot status

```javascript
const EnableBotStatusMessages = true;
const BotStatusMessages = ["Welcome to {servername}!", "{playercount} players online.", "Join at {invite}"];
```

Placeholders: `{servername}`, `{playercount}`, `{invite}`.

### Auto ACE permissions

```javascript
const EnableAutoAcePermissions = true;
const AutoAcePermissions = {
  "group.admin": "DISCORD_ROLE_ID",
  "group.moderator": ["ROLE_ID_1", "ROLE_ID_2"],
};
```

### Webhook logging

```javascript
const EnableLoggingWebhooks = true;
const LoggingWebhookName = "Server Logs";
const LoggingAlertPingId = "&ROLE_ID";
const LoggingWebhooks = { "bank": "https://...", "admin": "https://...", "death": "https://..." };
```

### Convars alternative

Instead of editing `config.js`, set values in `server.cfg`: `set discord_token "..."`, `set discord_guild_id "..."`, `set discord_enable_whitelist true`, `set discord_whitelist_roles "..."`, and so on.

## Commands reference

**General:** `/help`, `/onlinecount`, `/server` — all `user`.

**Player management:** `/players` (mod), `/message` (mod), `/kick` (mod), `/kickall` (admin), `/kill` (admin), `/ban add|remove|list` (admin), `/announcement` (mod). Context menu: right-click a user → **Check Online** (mod).

**VorpCore** (requires VorpCore loaded before the bot): `/playerinfo`, `/heal`, `/revive` (admin), `/currency give|take` (admin), `/inventory give|take|inspect` (admin), `/job set|remove|view` (admin), `/permissions add|remove|view` (founder).

**Server:** `/resource start|stop|ensure|refresh|list|inspect` (founder), `/time` (admin), `/weather get|set|forecast` (admin), `/whitelist toggle|addrole|removerole` (founder).

**Utility:** `/embed simple|complex` (founder).

**In-game:** `/staff <message>` (ACE `cas_adminbot.staffchat`), `/stafftoggle` (Discord staff role).

## Extending the bot

The bot is modular — drop `.js` files into the right folder and they load automatically.

### Commands (`server/commands/*.js`)

```javascript
module.exports = {
  name: "yourcommand",
  description: "What your command does",
  role: "mod",                 // user | mod | admin | founder
  type: "CHAT_INPUT",          // or USER / MESSAGE (context menus)
  options: [ { name: "parameter", description: "...", required: true, type: "STRING" } ],
  run: async (client, interaction, args) => {
    return interaction.reply({ content: `Result: ${args.parameter}`, ephemeral: false });
  },
};
```

Option types: `STRING`, `INTEGER`, `NUMBER`, `BOOLEAN`, `USER`, `CHANNEL`, `ROLE`, `SUB_COMMAND`, `SUB_COMMAND_GROUP`. Inside `run` you get `client.config`, `client.utils` (logging, `sleep`, identifier helpers, `chatMessage`, `replaceGlobals`), `client.VorpCore` and `client.Embed`.

### Events (`server/events/*.js`)

```javascript
module.exports = {
  name: "messageCreate",   // any discord.js event name
  once: false,
  run: async (client, ...args) => { /* handle event */ },
};
```

Common events: `ready`, `messageCreate`, `interactionCreate`, `guildMemberAdd`, `guildMemberRemove`, `guildMemberUpdate`, `guildBanAdd`, `guildBanRemove`.

### Addons (`server/addons/*.js`)

Classes instantiated at startup, reachable at `client.cas.youraddon`:

```javascript
class YourAddon {
  constructor(cas) { this.cas = cas; this.utils = cas.utils; this.init(); }
  init() { this.utils.log.info("YourAddon initialized!"); }
}
module.exports = YourAddon;
```

The built-in `log` addon exposes webhook logging to other resources.

## Exports

Available to other resources:

* `isRolePresent(identifier, role)` → boolean (role = single id or array of ids)
* `getRoles(identifier)` → array of role ids
* `getName(identifier)` → Discord display name, or `false`
* `getDiscordId(identifier)` → Discord id, or `false`

Example — whitelist gate:

```lua
local hasWL = exports['cas_adminbot']:isRolePresent(source, { "WL_ROLE_1", "WL_ROLE_2" })
```

Example — webhook log from another resource:

```lua
exports['cas_adminbot']:log("admin", {
  title = "Player Banned", message = "A player was banned",
  fields = { { name = "Player", value = playerName, inline = true } },
  color = 16711680, ping = true,
})
```

## Logging

Use `client.utils.log.info | warn | error | log | write`. Log format:

```
[cas_adminbot][2025-10-25 12:30:45][TAG]: Message
```

## Troubleshooting

* **`[TOKEN_INVALID]`** — regenerate the token in the Developer Portal and update `config.js`.
* **`[DISALLOWED_INTENTS]`** — enable both privileged intents (Server Members + Message Content).
* **`DiscordGuildId was not found`** — check your server ID (Developer Mode → Copy ID).
* **Commands don't appear** — enable slash commands, re-invite with `applications.commands`, then wait for Discord to register them.
* **Whitelist not working** — enabled? correct role IDs? player has Discord open?
* **VorpCore commands missing** — VorpCore must load **before** `cas_adminbot`.
* **Discord ID not detected** — the player must have the Discord desktop app open before launching RedM.

## Support

Join the support Discord or contact CAS through your purchase platform. This product is licensed per client; redistribution is prohibited.
