Trying to send an embed to a webhook to Discord

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to send an embed to a Discord server using a webhook through a proxy.

  2. What is the issue? I get an HTTP 400 (Bad Request) error whenever the button is clicked on.

image

local HTTPService = game:GetService("HttpService")
local URL = "https://hooks.hyra.io/api/webhooks/youcannotaccessmywebhookthateasily"

script.Parent.MouseClick:Connect(function(player)
	local Data = {
		["embeds"] = {
			["title"] = "Button was clicked!",
			["description"] = player.Name.." clicked the button!",
			["color"] = 15158332
		}
	}
	
	local JSON = HTTPService:JSONEncode(Data)
	local success, errormessage = pcall(function()
		HTTPService:PostAsync(URL, JSON, Enum.HttpContentType.ApplicationJson)
	end)
	
	if success then
		warn("Webhook was successfully sent over!")
	else
		warn(errormessage)
	end
end)

Maybe I should use a different proxy? What should I use?

Update: I tried to use this proxy as well but the error still occured: https://webhook.lewisakura.moe/

The problem is probably with your request’s body. I visited discohook.org and made a basic embed to see how it would look in JSON.

image

I noticed that each embed has to be wrapped in another pair of brackets

image

So here’s how it should look like in your situation

local Data = {
	["embeds"] = {
		{
			["title"] = "Button was clicked!",
			["description"] = player.Name.." clicked the button!",
			["color"] = 15158332
		}
	}
}

Not sure if you need to define the content even if you don’t have any.

By the way, the issue is not with your proxy. Error 400 usually means that your request was invalid.

I hope this fixes your issue.

1 Like

Thank you!! I’m gonna have a lot of fun with webhooks now.

1 Like

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