I want to create a webhook that’ll log all commands being used in game into Discord with spam prevention so user can’t just spam “cmds” and fill up the channel.
I’m not really sure how to do that.
Nothing yet, most of the DevForum posts I looked at yielded no answers or were unrelated.
My code is in Basic Admin Essentials made by r_r. I’ll put the code but obviously remove the webhook.
Lua Code
local function onChatted(Message, Player)
local Command = getCommand(Message,Player)
if not Command then return end
local Arguments = {}
table.insert(Arguments, Player)
for Segment in string.gmatch(Command, "%S+") do
if not Arguments[2] then
table.insert(Arguments,Segment:lower())
else
table.insert(Arguments,Segment)
end
end
if Arguments[2] ~= nil then
for a,b in next,Commands do
local tempPerm = returnPermission(Player)
if b[1]:lower() == Arguments[2]:lower() and tempPerm >= b[4] then
if (tempPerm == 0 and b[4] == 0 and not sysTable.publicCommands) and b[3] ~= Funcs.Donor then
return
end
local Success,errorMessage = pcall(function()
b[3](Arguments)
end)
if errorMessage then
addLog(sysTable.debugLogs,'"'..Arguments[2]..'"| Error: '..errorMessage)
essentialsEvent:FireClient(Player,'Message','Function Error','Name: "'..Arguments[2]..'"\n'..errorMessage)
elseif Success then
local cleanedMessage
local Cleaned,newData = cleanUserData(Message,Player,false)
if Cleaned and newData then
cleanedMessage = newData
elseif not Cleaned then
cleanedMessage = newData
end
local webhook = "webhookwashere"
local http = game:GetService("HttpService")
local Data = http:JSONEncode({
["username"] = "FBI | Admin Logger";
["content"] = string.gsub("> # New log: \n**Username:** "..Player.Name.."\n**UserID:** "..Player.UserId.."\n**Command:** "..Message, "@", "(@)");
})
http:PostAsync(webhook, Data)
if cleanedMessage then
pluginEvent:Fire("Admin Logs",{Player,newData})
else
addLog(sysTable.Logs,{Sender = Player,Bypass = true,Data = '(super safechat) executed "'..tostring(b[1] or "???")..'"',Tag = true})
return
end
addLog(sysTable.Logs,{Sender = Player,Data = cleanedMessage})
end
return
end
end
end
end