Discord Webhook HTTP 400 Error

Hello Devs, I am currently trying to make a report system in my game which uses Discord Webhooks but I’m facing a problem here.

I got my Server Script ready and all, but when I try execute the script, I get a HTTP 400 error which happens when I format something wrong.

This is the script:

local ls = game:GetService("LocalizationService")
local http = game:GetService("HttpService")
local player = game:GetService("Players").PlayerAdded:Wait()
local region = ls:GetCountryRegionForPlayerAsync(player)
local Countries = require(script.Countries)
local success, code = pcall(ls.GetCountryRegionForPlayerAsync, ls, player)

game.ReplicatedStorage.ColorChange.OnServerEvent:Connect(function()
	if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Bug" then
		player.PlayerGui.SettingsMenu.Report.Color.Value = 16730955
	end
	if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Other" then
		player.PlayerGui.SettingsMenu.Report.Color.Value = 4960255
	end
	if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Player" then
			player.PlayerGui.SettingsMenu.Report.Color.Value = 4980555
	end
end)

game.ReplicatedStorage.Report.OnServerEvent:Connect(function(player, report, dropdown)
	local data = {
		["embeds"] = {

			["title"] =	"Click to join Player server".." - "..dropdown,
			["description"] = report,
			["url"] = "roblox://experiences/start?placeId=13822889&gameInstanceId="..game.JobId.."",
			["color"] = game.StarterGui.SettingsMenu.Report.Color.Value,
			
			["fields"] = {
				["name"] = "Sent Date:",
				["value"] = ":flag_"..region..": "..Countries[code]..""
			}	
		},
	}
print(player.PlayerGui.SettingsMenu.Report.Color.Value)
print(Countries[code])
data = http:JSONEncode(data)
	http:PostAsync("https://discord.com/api/webhooks/Webhook_link", data) -- line 38
end)

The error

SOLUTION

The issue was, that Roblox did not accept any link other than http/https meaning this was the issue
image

Instead of roblox://experiences/start… you can put an external link that will redirect to the same link

https://deeplink.multicrew.dev/?placeId=PLACEID&jobId=JOBID

Thanks to @Redusofficial

HTTP 400 = bad request

It’s likely this. If that is a Color3 value, it will return bad request with the embed because unlike discord bots with their appropriate modules, webhooks do not accept rgb or hexadecimal values. You need to give it the integer representation. For example, Color3 255, 170, 0 becomes 16755200.

1 Like

Yes, this means that the data you sent had the wrong format, more or less. I could also imagine that roblox does not allow requests to discord.

You can use external software like curl (terminal) or Postman (executable) to debug your request arguments.

I don’t mean to immediately shoot down other suggestions but I would just like to clarify on this. It seems discord has recently unblocked requests from roblox servers as I and many others are able to put the webhook URL directly in scripts and have it function correctly without the use of a proxy service. They were previously blocked, so just to clear up confusion for others also viewing this topic, it likely is not this.

it would also be HTTP 403 (Forbidden) if that were the case!

I’ve seen my fair share of misleading roblox errors. And that wasn’t my main point anyway so, yeah maybe idk.

1 Like

i was aware about the different color code, the …Color.Value is inside a playerGui
image
the numbers here are the integer values, im thinking that the server script probably cant see or edit the value inside the player’s gui

Try printing out the colour before the request is sent. I also noticed some other things:

  1. Each field should be a nested table, which will then be converted to a JSON array.
  2. I think you need the inline value as well, for the field.
1 Like

I don’t really understand the first point
if you check on this website, you can see that the fields thing can have two different “states”, one inline and one non inline

It’s basically adding each one as it’s own component.
For example, here using discord.js to send a message through a bot, you can see for embeds we need each value as it’s own array.

//ignore this bit
let embed = new EmbedBuilder()
.setTitle("Embed")
.setDescription("Description")
.setColor(0xff8500)

//this is the bit you need to notice
.addFields(
    //notice here how each field is it's own dictionary. They are seperate 
    {name: "field", value: "value", inline: true},
    {name: "field2", value: "value2", inline: true}
)


channel.send({embeds: [embed]})

This contradicts to your code, where the fields dictionary is being used by your field, and does not contain a set of fields.
Try to format your field like this:

["fields"] = {
    --nested dictionary for the field
    {
        ["name"] = "Sent Date:",
        ["value"] = --etc with the country flag data
    }
}

Hm, that was a good thought but that unfortunately didn’t work
By the way, the 0 in the output window is the color value

Oh, wait. You know how I mentioned a nested table for each field element? I think you need to encase that entire embed in a table as well because of the same issue.

Posting your token publicly is kinda a bad idea.

@pinker_stinker5150 oopsies, forgot to hide it

game.ReplicatedStorage.Report.OnServerEvent:Connect(function(player, report, dropdown)
	local data = {
		["embeds"] = {
			{
				["title"] =	"Click to join Player server".." - "..dropdown,
				["description"] = report,
				["url"] = "roblox://experiences/start?placeId=boo&gameInstanceId="..game.JobId.."",
				["color"] = game.StarterGui.SettingsMenu.Report.Color.Value,
			
				["fields"] = {
					{
					["name"] = "Sent Date:",
						["value"] = ":flag_"..region..": "..Countries[code]..""
					}
				}	
			}
		},
	}

Nothing changed, it still gave me the same error

1 Like

It might be because the embed URL (protocol) is roblox://, I’m fairly sure discord only allows it to be https/http.

Try temporarily removing the URL to test this.

oh, it actually worked. After removing it the script works normally.
Do you know anything i can do to keep it?

Yes, there’s this external website that allows you to redirect to roblox://

https://deeplink.multicrew.dev/?placeId=PLACEID&jobId=JOBID

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.