Hey everyone, I have used webhook system by @gillern and I have encountered some issues. No errors are logged and I have been told discord no longer blocks roblox webhooks so I am not sure why this code does not work.
Client:
--Variables
local player = game.Players.LocalPlayer
--UI
local feedbackMain = script.Parent.FeedbackFrame
--Script
local zxc = script.Parent.FeedbackFrame.Frame.TextBox.InputBox.Text
script.Parent.FeedbackFrame.Frame.SendBtn.MouseButton1Click:Connect(function()
local msg = feedbackMain.Frame.TextBox.InputBox.Text
local response = game.ReplicatedStorage.FilteringFunction:InvokeServer(msg)
feedbackMain.Frame.TextBox.InputBox.Text = response
wait(5)
script.Parent.FeedbackFrame.Frame.TextBox.InputBox.Text = zxc
end)
script.Parent.FeedbackFrame.ToggleBtn.MouseButton1Click:Connect(function()
script.Parent.FeedbackFrame.Frame.Visible = not script.Parent.FeedbackFrame.Frame.Visible
end)
Server:
--SETUP
local webhook = "https://discordapp.com/api/webhooks"
--Variables
local filteringFunction = game.ReplicatedStorage.FilteringFunction
--Services
local HTTP = game:GetService("HttpService")
local CHAT = game:GetService("Chat")
function filteringFunction.OnServerInvoke(player, msg)
local payload = HTTP:JSONEncode({
content = CHAT:FilterStringForBroadcast(msg,player),
username = player.Name.." - (#"..player.UserId..")"
})
HTTP:PostAsync(webhook, payload)
return "Feedback recieved!"
end
It returns “Feedback received” but the webhook doesnt go through
When JSON encoding, you can’t use “content = 123”, you need to use “[“content”] = 123”.
Make sure you double check your variables for this issue.
While I don’t have experience with this API, I’ve used many similar ones. Your code looks good as far as I can tell except that your webhook URL is missing both the webhook id and token. Did you intentionally remove it for this post or was it forgotten in the source as well?
As far as debugging goes, I’d first check the payload string and make sure it matches what is expected. If so I’d change HTTP:PostAsync to the more modern HTTP:RequestAsync. This will return a dictionary with much more information about what happened during the request. If you post the deep print of the returned dictionary, we may be able to help you more.
That is strange. Are you sure your webhook token is correct? Also you realize that the way you are sending feedback to your discord server is unsafe? Someone can literally just spam the remote function and make the http service throw errors. Not only that but you should wrap your http service requests in pcalls as they can error. Can you try adding
print(InformationToSend)
Below the part where you JSON encode the dictionary, send a screenshot of the output.
When you Invoke the server, the first argument will always be the player, no matter what. That’s the same with RemoteEvents when you :FireServer() the server.