Koja Scripts
KOJA-LIB

Webhooks

koja-lib includes a built-in Discord webhook logger.

Webhooks

koja-lib includes a built-in Discord webhook logger.

Configuration

Add webhook URLs to the KOJA.Server.Webhooks table in server/webhook.lua:

KOJA.Server.Webhooks = {
    ['cardealer'] = 'https://discord.com/api/webhooks/...',
    ['main']      = 'https://discord.com/api/webhooks/...',
    ['police']    = 'https://discord.com/api/webhooks/...',
}

Each key is a channel name you choose. You can add as many as you need.

LogMessage

Send a message to a Discord webhook channel.

KOJA.Server.LogMessage(data, channel)
ParameterTypeDescription
datatableMessage data
data.messagestringEmbed description (supports Discord markdown)
data.titlestring?Embed title
data.footertextstring?Embed footer
channelstringWebhook key from KOJA.Server.Webhooks

Example

KOJA.Server.LogMessage({
    title       = 'Vehicle Purchased',
    message     = ('**Player:** %s\n**Vehicle:** %s\n**Plate:** %s\n**Price:** $%d'):format(
        GetPlayerName(source),
        'Adder',
        plate,
        500000
    ),
    footertext  = 'car-dealer',
}, 'cardealer')

Example Output

The webhook sends a Discord embed that looks like:

Vehicle Purchased
──────────────────
Player: John Doe
Vehicle: Adder
Plate: ABCD1234
Price: $500,000
──────────────────
car-dealer

Adding Channels

Open server/webhook.lua and add entries to the table:

KOJA.Server.Webhooks = {
    ['cardealer'] = 'https://discord.com/api/webhooks/111/aaa',
    ['heist']     = 'https://discord.com/api/webhooks/222/bbb',
    ['admin']     = 'https://discord.com/api/webhooks/333/ccc',
}

Then use the key when calling LogMessage:

KOJA.Server.LogMessage({ message = 'Heist started', title = 'Heist' }, 'heist')
  • Getting Started — Configuration and Installation for Getting Started.
  • API Reference — Client API and Server API for API Reference.
  • Frameworks — Custom Framework and Overview for Frameworks.
  • Inventory — Custom Inventory and Overview for Inventory.
  • Weapon — Utility function for reading the player's current weapon state.
  • Text UI — A small on-screen prompt that shows an action key and a label.