I have a problem with the DISCORD webhooks, I have already tried to send a manual request from the cmd and if it works, but not here, I do not know where the error is, attached error that comes out in the host console (The discord bot name is CASH) so ¿Where is the error?
-- Function to send the message to Discord
function sendDiscordLog(message)
if not webhookURL then
outputDebugString("[Discord] Error: webhookURL is not configured")
return
end
-- Manually construct the JSON in the correct format
local postData = string.format(
'{"username":"MONEY","content":"%s","avatar_url":".png"}',
message
)
outputDebugString("[Discord] Attempting to send: " .. postData)
fetchRemote(webhookURL,
function(responseData, responseInfo)
outputDebugString("[Discord] Status: " .. tostring(responseInfo))
if responseData then
outputDebugString("[Discord] Full response: " .. tostring(responseData))
end
if responseInfo == 400 then
outputDebugString("[Discord] Error 400 - Check message format")
outputDebugString("[Discord] Sent data: " .. postData)
end
end,
"POST", -- Correct HTTP method
postData, -- Properly formatted JSON
true, -- IMPORTANT: This parameter is a boolean and must be present
{["Content-Type"] = "application/json"} -- Valid JSON header
)
end
-- Test command
addCommandHandler("testwebhook", function()
sendDiscordLog("Test message from MONEY")
end)
- ERROR
[06:18:56] INFO: [Discord]Trying to sent:{"username":"CASH","content":"Test MSG from CASH","avatar_url":".png"}[06:18:56] WARNING: [Economia]/server.lua:51: Bad argument @ 'fetchRemote' [Expected bool at argument 4, got string '{"username":"CASH","content":"Test MSG from CASH","avatar_url":".png"}']
I have tried almost EVERYTHING from CMD Request, to checking letter by letter the webhook link and it works so the error is in the code.
I don’t know ¿Where is the error? so if somebody see it, please notify.