HTTP 400 (Bad Request) Webhook Error Help

Hi, so I’ve been stuck on this for the past couple hours. I have created a module to send webhooks to Discord and I keep getting the HTTP 400 (Bad Request) error.

My current code:

local module = {}

local DonationWebhook = "https://hooks.hyra.io/api/webhooks/SOMEWEBHOOKSTRING"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FormatNumber = require(ReplicatedStorage.Modules.FormatNumber)

local HTTP = game:GetService("HttpService")

function module.SendDonationWebhook(amount,donor,receiverName,receiverId,color)
	
	local DonateString = "Donated R$"..FormatNumber.Comma(amount).." to "..receiverName.." ("..receiverId..")"
	local DaysString = FormatNumber.Comma(donor.AccountAge).. " days"
	
	local data = {["embeds"] = {{
		["author"] = {
			["name"] = donor.Name,
			["icon_url"] = game:GetService("Players"):GetUserThumbnailAsync(donor.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
		},

		["description"] = DonateString,
		["color"] = color,

		["fields"] = {
			{
				["name"] = "Donor Account Age",
				["value"] = DaysString,
				["inline"] = true
			},
			{
				["name"] = "Donor User ID",
				["value"] = tostring(donor.UserId),
				["inline"] = true
			}
		}
	}}}	
	
	local enData = HTTP:JSONEncode(data)
	
	print(enData)
	
	HTTP:PostAsync(DonationWebhook, enData)
end

return module

When printing the encoded data I get:

{"embeds":[{"color":16711680,"author":{"icon_url":"rbxthumb://type=AvatarHeadShot&id=71846238&w=150&h=150","name":"Ayntrx"},"description":"Donated R$250,000 to Ayntrx (71846238)","fields":[{"value":"2,831 days","name":"Donor Account Age","inline":true},{"value":"71846238","name":"Donor User ID","inline":true}]}]}

This doesn’t seem to be an error with the way I’m formatting the data as I have pasted the above into the Discord embed visualizer with no errors and the webhook is formatter correctly. This also doesn’t seem to be an issue with the proxy I am using as it is working in some of my other games.

1 Like

The reason why this is happening is because under the author field, the icon_url field contains a ROBLOX thumbnail URL that looks like this rbxthumb://type=AvatarHeadShot&id=71846238&w=150&h=150.

This is not accepted by discord webhooks. The URL must use a universal protocol like Https . You can see if you try the exact same code but with a hardcoded Https URL then it works.

local module = {}

local DonationWebhook = "https://hooks.hyra.io/api/webhooks/SOMEWEBHOOKSTRING"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FormatNumber = require(ReplicatedStorage.Modules.FormatNumber)

local HTTP = game:GetService("HttpService")

function module.SendDonationWebhook(amount,donor,receiverName,receiverId,color)
	
	local DonateString = "Donated R$"..FormatNumber.Comma(amount).." to "..receiverName.." ("..receiverId..")"
	local DaysString = FormatNumber.Comma(donor.AccountAge).. " days"
	
	local data = {["embeds"] = {{
		["author"] = {
			["name"] = donor.Name,
			["icon_url"] = "https://imgs.search.brave.com/7mmI4qVypqLNu9Gkvhag5Ss9BNU8YVz7UvAK9pA8HjY/rs:fit:1200:1200:1/g:ce/aHR0cHM6Ly93d3cu/Z2FubmV0dC1jZG4u/Y29tLy1tbS0vZmEy/YWExNTJhYzQ1YTRk/NmViOTNkMzQ5NWRm/ZTFlYTMwZTkxOGM1/Ny9jPTAtNTg1LTMy/OTItMjQ0NS9sb2Nh/bC8tL21lZGlhLzIw/MTYvMDgvMjMvUGhv/ZW5peC9QaG9lbml4/LzYzNjA3NTcwNTI2/MzM2MjkzMS1UaGlu/a3N0b2NrUGhvdG9z/LTg3NzQ5NTc2Lmpw/Zz93aWR0aD0zMjAw/JmhlaWdodD0xODA5/JmZpdD1jcm9wJmZv/cm1hdD1wanBnJmF1/dG89d2VicA"
		},

		["description"] = DonateString,
		["color"] = color,

		["fields"] = {
			{
				["name"] = "Donor Account Age",
				["value"] = DaysString,
				["inline"] = true
			},
			{
				["name"] = "Donor User ID",
				["value"] = tostring(donor.UserId),
				["inline"] = true
			}
		}
	}}}	
	
	local enData = HTTP:JSONEncode(data)
	
	print(enData)
	
	HTTP:PostAsync(DonationWebhook, enData)
end

return module

This means you will need to find a way to get the player’s thumbnail URL in a URL that Discord supports.

1 Like

Discord still blocks requests from roblox

1 Like

My bad, I’ve removed that from my post.

Thanks! I didn’t notice that at first, but I got it to work through use of a proxy so I could get the users thumbnail image from the roblox api!

1 Like

For further context regarding the solution.

1 Like