HTTP 400 (Bad Request) - Discord Webhook

whatever I do, it doesn’t work anyway, I checked everything about 30 times and it still shows me an HTML 400 error.

Code:

	local HttpData = {
		embeds = {
			{
				title = "A Secret weapon was earned!",
				color = 16720621,
				fields = {
					{
						name = "Player",
						value = "1",
						inline = true
					},
					{
						name = "Weapon",
						value = "2",
						inline = true
					},
					{
						name = "Rarity",
						value = "3",
						inline =  true
					}
				},
				thumbnail = {
					url = "https://media.discordapp.net/attachments/--" -- hidden
				}
			}
		}
	}
	local Success, Failure = pcall(function()
		game.ReplicatedStorage:WaitForChild("PostDiscordMessageAsync"):InvokeServer(game:GetService("HttpService"):JSONEncode(HttpData))
	end)
	if not Success then
		warn(Failure)
	end
1 Like

game.ReplicatedStorage:WaitForChild("PostDiscordMessageAsync"):InvokeServer(game:GetService("HttpService"):JSONEncode(HttpData))
What server-side code is this invoking?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")

local Url = "https://discord.com/api/webhooks/" -- hidden

local RemoteFunction = Instance.new("RemoteFunction")
RemoteFunction.Name = "PostDiscordMessageAsync"
RemoteFunction.Parent = ReplicatedStorage

function RemoteFunction.OnServerInvoke(Player, Data)
	HttpService:PostAsync(Url, HttpService:JSONEncode(Data))
end

Replace HttpData with this, it should work.

	local HttpData = {
		embed = {
				title = "A Secret weapon was earned!",
				color = 16720621,
				fields = {
					{
						name = "Player",
						value = "1",
						inline = true
					},
					{
						name = "Weapon",
						value = "2",
						inline = true
					},
					{
						name = "Rarity",
						value = "3",
						inline =  true
					}
				},
				thumbnail = {
					url = "https://media.discordapp.net/attachments/--" -- hidden
				}
		}
	}

I just noticed that I used HttpService:JSONEncode() 2 times.

1 Like

Yeah, that’ll do it. If you just remove one of the two JSONEncode() and use the HttpData I posted above I think your issue should be gone.

Please don’t trust the client to make blind HTTP Requests [body wise]

2 Likes

yes, I noticed, I probably must have been sleepy then