HTTP 400 (Bad Request) with Discord Webhook

Im getting a Bad Request Error and i dont know whats wrong. I have enabled the HTTP requests in my game

local url = "Webhook1"
local url2 = "Webhook2"
local http = game:GetService("HttpService")
local RepStor = game:GetService("ReplicatedStorage")
local WebhookEvent = RepStor.WebhookEvent

WebhookEvent.OnServerEvent:Connect(function(Player,DataFromClient,AppType,GMScript)
	if AppType == "2DGM" then
		local Data2 = {
			["content"] = "",
			["embeds"] = {{
				["title"] = "title",
				["description"] = "Player: "..Player.Name,
				["type"] = "rich",
				["color"] = tonumber(0xffffff),
				["fields"] = {
					{
						["name"] = "test",
						["value"] = DataFromClient,
						["inline"] = true
					},
					
					{
						["name"] = "test",
						["value"] = GMScript,
						["inline"] = true
					}
				}
			}}
		}

		local FinishedData = http:JSONEncode(Data2)
		http:PostAsync(url2,FinishedData)
		
	elseif AppType == "SCED" then
		local Data = {
			["content"] = "",
			["embeds"] = {{
				["title"] = "title",
				["description"] = "Player: "..Player.Name,
				["type"] = "rich",
				["color"] = tonumber(0xffffff),
				["fields"] = {
					{
						["name"] = "test2",
						["value"] = DataFromClient,
						["inline"] = true
					}
				}
			}}
		}

		local FinishedData = http:JSONEncode(Data)
		http:PostAsync(url,FinishedData)
	end
end)
1 Like

Discord blocked roblox from using their webhooks. Sorry

i have a other game were the webhook still works

1 Like

I think its new webhooks. Not old ones. Theres no work a round unless u use the old one.

1 Like

Discord Servers actively block requests from Roblox Servers. This will work in studio because the request is coming from your computer. If you want to bypass this, there is a proxy or you can use mySQL / external site and send your data over there, from there you can send it to discord but its a lot of jargon, I recommend you use the proxy.

This will work unless there are too many requests, so I recommend you make a queue system.

Also HTTP 400 Bad request means that there is something wrong with your code, so I recommend you debug it and see where you went wrong.

It fails at the http:PostAsync(url2,FinishedData) part, and idk how to fix it

[‘content’]
[‘description’]

Pretty sure you need to have one quotation mark

replaced the " with ’ but im still getting a 400

@Zenqpa It does not matter whether they use ’ or " in Lua as both define strings.


@Happygamer1983 You do not have to specify the embed type. Also, are you sure DataFromClient or GMScript exists? Can you post the script where you are firing the RemoteEvent?

the DataFromClient and GMScript exist and the scipt where im firing the Remote Event i think is too long to post here

You can post the scripts on Pastebin then send the link here.

here is the Pastebin, the part were im firing the Event is from line 33 to 62

Can you try printing DataFromClient and GMScript before sending the request?

DataFromClient:
{
[1] = TextButton,
[2] = Frame
}
GMScript:

<font color="rgb(102,102,102)">--[[ INFO: [name here] ]]</font><font color="rgb(102,102,102)">--

</font><font color="rgb(102,102,102)">-- Your Window is at: 
</font><font color="rgb(102,102,102)">--script.Parent.Parent.[Project Name].MainFrame
</font><font color="rgb(102,102,102)">-- Please put your project name in the [name here]!

</font><font color="rgb(248,109,124)">local </font><font color="rgb(204,204,204)">Frame </font><font color="rgb(204,204,204)">= </font><font color="rgb(132,214,247)">script</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Parent</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Parent</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Default</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">MainFrame</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Frame
</font><font color="rgb(248,109,124)">local </font><font color="rgb(204,204,204)">Button </font><font color="rgb(204,204,204)">= </font><font color="rgb(132,214,247)">script</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Parent</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Parent</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Default</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">MainFrame</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">TextButton
</font><font color="rgb(248,109,124)">local </font><font color="rgb(204,204,204)">IsOpen </font><font color="rgb(204,204,204)">= </font><font color="rgb(248,109,124)">false

</font><font color="rgb(204,204,204)">Button</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">MouseButton1Click</font><font color="rgb(204,204,204)">:</font><font color="rgb(204,204,204)">Connect</font><font color="rgb(204,204,204)">(</font><font color="rgb(248,109,124)">function</font><font color="rgb(204,204,204)">()
 </font><font color="rgb(248,109,124)">if </font><font color="rgb(204,204,204)">IsOpen </font><font color="rgb(204,204,204)">== </font><font color="rgb(248,109,124)">false </font><font color="rgb(248,109,124)">then
  </font><font color="rgb(204,204,204)">Frame</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Visible </font><font color="rgb(204,204,204)">= </font><font color="rgb(248,109,124)">true
  </font><font color="rgb(204,204,204)">IsOpen </font><font color="rgb(204,204,204)">= </font><font color="rgb(248,109,124)">true
 </font><font color="rgb(248,109,124)">else
  </font><font color="rgb(204,204,204)">Frame</font><font color="rgb(204,204,204)">.</font><font color="rgb(204,204,204)">Visible </font><font color="rgb(204,204,204)">= </font><font color="rgb(248,109,124)">false
  </font><font color="rgb(204,204,204)">IsOpen </font><font color="rgb(204,204,204)">= </font><font color="rgb(248,109,124)">false
</font><font color="rgb(248,109,124)">end
</font><font color="rgb(248,109,124)">end</font><font color="rgb(204,204,204)">)</font>

The expected type for the value of a field is a string, but DataFromClient is an array.

Reference: Discord Developer Portal

the DataFromClient gets encoded using HTTPService so it can be saved for later use

When you encode your request body, DataFromClient is an array in JSON, not a string.

no i mean it gets the proberties of the Object and encodes them with HTTPSevice and then is gets send to the Script which sends it to the Webhook, so the DataFromClient should be a string and if not could i use tostring() ?

Discord blocked webhooks from Roblox because people were abusing them. (Spamming them.)

When you print DataFromClient, is it an array?