Help RAKSAMP .LUA SCRIPT

unknown47832

Member
Joined
Nov 2, 2025
Messages
6
Reaction score
1
Bro how the fuck do I make a discord webhook.lua work with raklaunch lite (it supports scripts and .lua) so i can get whole chatlog of my server on discord channel in REAL TIME, i'm just dumb asf i guess, has anyone ever added scripts to raksamp and made it work
 

unknown47832

Member
Joined
Nov 2, 2025
Messages
6
Reaction score
1
1762114827255.png]
this is the error, and no, chatgpt didnt help me at all it just fucks things up and makes it overcomplicated

edit: btw this is the folder where raklaunch lite is, lmk if something is missing?}
1762114921923.png
 

Expl01T3R

Active member
Joined
Nov 20, 2022
Messages
187
Solutions
1
Reaction score
40
Location
Czech Republic
I made working example, but it launches curl process (via cmd) every webhook request.. if u have requests module it could be made easier.
Also you gotta modify the webhook url settings.

Python:
require 'addon'

local ev = require 'samp.events'

-- Discord webhook settings
local WEBHOOK_URL = "https://discord.com/api/webhooks/..."
local BOT_NAME = "Name"

-- Send a message to Discord webhook (non-blocking via start)
local function sendWebhook(user, text)
    -- Escape double quotes and backslashes for safe JSON
    text = text:gsub('\\', '\\\\'):gsub('"', '\\"')
    local payload = string.format([[{"username":"%s","content":"%s"}]], user, text)

    -- Run curl silently without blocking (Windows)
    local cmd = string.format(
        'start "" /B curl -s -X POST -H "Content-Type: application/json" -d "%s" "%s"',
        payload,
        WEBHOOK_URL
    )

    os.execute(cmd)
end

-- Remove SA:MP color codes like {FFFFFF}
local function cleanText(text)
    return text:gsub("{......}", "")
end

-- Called when the server sends a message
function ev.onServerMessage(color, text)
    sendWebhook(BOT_NAME, cleanText(text))
end

-- Called when player writes a message
function ev.onChatMessage(playerId, text)
    sendWebhook(BOT_NAME, cleanText(text))
end
 

unknown47832

Member
Joined
Nov 2, 2025
Messages
6
Reaction score
1
if u have requests module it could be made easier.
How and where do I get this module ? I'm so eager to make this work but everything I tried either didn't work or my RakLaunch Lite crashed after succesfully loading the script, also I found this, is this gonna help me with installation process somehow?

1762156986058.png
1762157049243.png
(it also has this inside of it)
 

unknown47832

Member
Joined
Nov 2, 2025
Messages
6
Reaction score
1
And here is the code of script that I have


Python:
require'addon'
local inicfg = require 'config'

local inidir = 'Discord Webhook'
local cfg = inicfg.load({
    main = {
        name = "Name",
        url = "[URL]https://discord.com/api/webhooks/[/URL]..."
    }}, inidir)
    inicfg.save(cfg, inidir)

local effil = require('effil')
    local function asyncHttpRequest(method, url, args, resolve, reject)
        local request_thread = effil.thread(function (method, url, args)
            local requests = require 'requests'
            local result, response = pcall(requests.request, method, url, args)
            if result then
                response.json, response.xml = nil, nil
                return true, response
            else
                return false, response
            end
        end)(method, url, args)
    if not resolve then resolve = function() end end
if not reject then reject = function() end end
newTask(function()
    local runner = request_thread
    while true do
        local status, err = runner:status()
        if not err then
            if status == 'completed' then
                local result, response = runner:get()
                if result then
                    resolve(response)
                else
                    reject(response)
                end
                return
            elseif status == 'canceled' then
                return reject(status)
            end
        else
            return reject(err)
        end
        wait(0)
    end
end)
end

local function sendwebhook(user, text)
    local newData = string.format([[
        {
            "username": "%s",
            "content": "%s"
        }
    ]], user, text)
    asyncHttpRequest(
        'POST',                        
        cfg.main.url,                 
        {                            
            headers = {
                ['content-type'] = 'application/json'
            },
            data = newData         
        },
        nil,                           
        nil                           
    )
end

    local ev = require 'samp.events'
    function ev.onServerMessage(col, text)
 
        local text = text:gsub("{......}", "")

        sendwebhook(cfg.main.name, text)

    end

    function ev.onChatMessage(id, text)
 local text = text:gsub("{......}", "")


        sendwebhook(cfg.main.name, text)

    end
 

unknown47832

Member
Joined
Nov 2, 2025
Messages
6
Reaction score
1
I made working example, but it launches curl process (via cmd) every webhook request.. if u have requests module it could be made easier.
Also you gotta modify the webhook url settings.

Python:
require 'addon'

local ev = require 'samp.events'

-- Discord webhook settings
local WEBHOOK_URL = "https://discord.com/api/webhooks/..."
local BOT_NAME = "Name"

-- Send a message to Discord webhook (non-blocking via start)
local function sendWebhook(user, text)
    -- Escape double quotes and backslashes for safe JSON
    text = text:gsub('\\', '\\\\'):gsub('"', '\\"')
    local payload = string.format([[{"username":"%s","content":"%s"}]], user, text)

    -- Run curl silently without blocking (Windows)
    local cmd = string.format(
        'start "" /B curl -s -X POST -H "Content-Type: application/json" -d "%s" "%s"',
        payload,
        WEBHOOK_URL
    )

    os.execute(cmd)
end

-- Remove SA:MP color codes like {FFFFFF}
local function cleanText(text)
    return text:gsub("{......}", "")
end

-- Called when the server sends a message
function ev.onServerMessage(color, text)
    sendWebhook(BOT_NAME, cleanText(text))
end

-- Called when player writes a message
function ev.onChatMessage(playerId, text)
    sendWebhook(BOT_NAME, cleanText(text))
end
I tried this code that you sent, it's succesfully loading script now and it does not crash but cmd is being opened every time there is a message and it's not being sent to discord webhook

 
Top