Webhook as esx_lscustom

I want to in esx_lscustom to add the webhook, as long as someone triggers it, there will be a notification… But I am a novice, I don’t know how to do it, can someone with good intentions teach me

There’s a language barrier, I believe. What do you mean by “join the webhook as esx_lscustom” ?

sorry…is in esx_lscustom to add the webhook

If they modify the vehicle in esx_lscustom, I want to be notified

Have you looked at one of the many discord resources to see how they handle a webhook?

2 Likes

Yes, i have looked at one of the many discord resources to see… but i still don’t understand, i tried it for a month

:slight_smile:

1 Like

1st of all, create a channel in your discord for logs, and a weebhok (options of the channel → integrations → create weebhok)
Then go to the server.lua of lscustom. Write on the top of the script this paragraph

local DISCORD_WEBHOOK = "yourweebhokhere" -- Here you need write the id of the weebhook copied in the options of the channel
local DISCORD_NAME = "nameofthebotasyouwant" -- Write the name as you want, example ls-logs
local STEAM_KEY = "yoursteamkey" -- Write here your steam key
local DISCORD_IMAGE = "image.jpgorpngasyouwant" -- This its optional if you wont let it empty

then go to the bottom of all the script and write this (dont change anything)

function sendToDiscord(name, message, color)
local connect = {
{
["color"] = color,
["title"] = "**".. name .."**",
["description"] = message,
["footer"] = {
["text"] = "",
},
}
}
PerformHttpRequest(DISCORD_WEBHOOK, function(err, text, headers) end, 'POST', json.encode({username = DISCORD_NAME, embeds = connect, avatar_url = DISCORD_IMAGE}), { ['Content-Type'] = 'application/json' })
end

Now find this trigger:

TriggerClientEvent('esx_lscustom:installMod', _source)

In my case there are 2, one taking money of society and other for players, nmv

then write bellow of them this

sendToDiscord(xPlayer..' has install a mod for '..price.."$")

like this

TriggerClientEvent('esx_lscustom:installMod', _source)
sendToDiscord('The mechanic'..xPlayer..' has install a mod for '..price.."$")

I hope helps!

2 Likes

hello I have tried to implement the webhook in the esx_lscustom script but it doesn’t work and I get the following error
esx_lscustom/server/main.lua:26: attempt to concatenate a table value (local ‘xPlayer’)

I would appreciate your help

Nobody can help you if you don’t post the code in question.

local DISCORD_WEBHOOK = “” – Here you need write the id of the weebhook copied in the options of the channel

local DISCORD_NAME = “ls_tuneos” – Write the name as you want, example ls-logs

–local STEAM_KEY = “” – Write here your steam key

–local DISCORD_IMAGE = “” – This its optional if you wont let it empty

ESX = nil

local Vehicles

TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)

RegisterServerEvent(‘esx_lscustom:buyMod’)

AddEventHandler(‘esx_lscustom:buyMod’, function(price)

local _source = source

local xPlayer = ESX.GetPlayerFromId(_source)

price = tonumber(price)

if Config.IsMechanicJobOnly then

    local societyAccount

    TriggerEvent('esx_addonaccount:getSharedAccount', 'society_mechanic', function(account)

        societyAccount = account

    end)

    if price < societyAccount.money then

        TriggerClientEvent('esx_lscustom:installMod', _source)

        sendToDiscord('The mechanic'..xPlayer..' has install a mod for '..price.."$")

        TriggerClientEvent('esx:showNotification', _source, _U('purchased'))

        societyAccount.removeMoney(price)

    else

        TriggerClientEvent('esx_lscustom:cancelInstallMod', _source)

        TriggerClientEvent('esx:showNotification', _source, _U('not_enough_money'))

    end

else

    if price < xPlayer.getMoney() then

        TriggerClientEvent('esx_lscustom:installMod', _source)

        sendToDiscord('The mechanic'..xPlayer..' has install a mod for '..price.."$")

        TriggerClientEvent('esx:showNotification', _source, _U('purchased'))

        xPlayer.removeMoney(price)

    else

        TriggerClientEvent('esx_lscustom:cancelInstallMod', _source)

        TriggerClientEvent('esx:showNotification', _source, _U('not_enough_money'))

    end

end

end)

RegisterServerEvent(‘esx_lscustom:refreshOwnedVehicle’)

AddEventHandler(‘esx_lscustom:refreshOwnedVehicle’, function(vehicleProps)

local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.fetchAll('SELECT vehicle FROM owned_vehicles WHERE plate = @plate', {

    ['@plate'] = vehicleProps.plate

}, function(result)

    if result[1] then

        local vehicle = json.decode(result[1].vehicle)

        if vehicleProps.model == vehicle.model then

            MySQL.Async.execute('UPDATE owned_vehicles SET vehicle = @vehicle WHERE plate = @plate', {

                ['@plate'] = vehicleProps.plate,

                ['@vehicle'] = json.encode(vehicleProps)

            })

        else

            print(('esx_lscustom: %s attempted to upgrade vehicle with mismatching vehicle model!'):format(xPlayer.identifier))

        end

    end

end)

end)

ESX.RegisterServerCallback(‘esx_lscustom:getVehiclesPrices’, function(source, cb)

if not Vehicles then

    MySQL.Async.fetchAll('SELECT * FROM vehicles', {}, function(result)

        local vehicles = {}

        for i=1, #result, 1 do

            table.insert(vehicles, {

                model = result[i].model,

                xPlayer = result[i].xPlayer,

                price = result[i].price

            })

        end

        Vehicles = vehicles

        cb(Vehicles)

    end)

else

    cb(Vehicles)

end

end)

function sendToDiscord(name, message, color)

local connect = {

    {

        ["color"] = color,

        ["title"] = "**".. name .."**",

        ["description"] = message,

        ["footer"] = {

        ["text"] = "",

    },

}

}

PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, content = message}), { ['Content-Type'] = 'application/json' })

end

1 Like