Roblox -> Discord Webhook Issue

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

2 Likes

Discord blocks the roblox user agent for Webhooks, so you’re unable to send webhooks unless you use a proxy service.

@Osyris Shut down his proxy because someone said they unblocked roblox requests… I guess that isn’t the case

Mine are working as they should, Ill look at my scripts in a few hours.

Roblox added ratelimit support for discord, and discord silently unblacklisted Roblox.

4 Likes

When using Http Service, you have to do ["content"] = instead of content =.

:lying_face: That should be it, I’ll test later.

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.

I’ve pulled up the documentation here:

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.

No change, still doesn’t work when I made the edits

Checked, still does not work, I get a 400 error

Updated server code (still does not work):

--SETUP
local webhook = "https://discordapp.com/api/webhooks//EdnUt7c---"

--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

Hello. This works perfectly for me.

local RemoteFunction = game.ReplicatedStorage.RemoteFunction
local HttpService = game:GetService("HttpService")
local ChatService = game:GetService("Chat")
local Webhook = "change this"

function RemoteFunction.OnServerInvoke(player, feedback)
	local InformationToSend = HttpService:JSONEncode({
		["content"] = ChatService:FilterStringForBroadcast(feedback, player),
		["username"] = player.Name.. " - (#"..player.UserId..")"
	})
	HttpService:PostAsync(Webhook, InformationToSend)
	return "Sent!"
end


If it is still not working for you, make sure you have enabled HTTP Requests.

Also, you should not use Discord for logging.

I have HTTP Requests enabled… hmm

I think you made a typo at:

local webhook = "https://discordapp.com/api/webhooks//EdnUt7c---"

notice how afet webhooks/ it has another slash? Also use request async not post async, it is better.

It’s correct, I just snipped part of it

Edit: May have made a typo on the client when invoking the server, I did (msg) instead of (player, msg)

EDIT: Still nothing

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.

Try the code that I provided to you.

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.

1 Like

As @JakyeRU said your server script should work, even though it is not secured well, can you send the client script?