Webhook - HTTP Error 400

It works, thanks! Do you know by chance what formatting might be wrong here as well? I keep getting error 400

Mentions = "<@1356282230967635969> <@1356282232746283140> <@1356282230577692854>"
Titles = PlayerRobloxUsername.."'s Level 0 Application"
Data = {
    ["contents"] = Mentions,
    ["url"] = "https://www.roblox.com/users/"..UserID.."/profile",
    ["embeds"] = {
        ["title"] = Titles,
        ["color"] = 8856607,
        ["thumbnail"] = {
        ["url"] = PlayerPicture
        },
        ["fields"] = {
              {
              ["name"] = "**"..MainGui.One.Question.Text.Text.."**",
              ["value"] = MainGui.One.Answer.TextBox.Text,
              ["inline"] = false
              },
              {
              ["name"] = "**"..MainGui.Two.Question.Text.Text.."**",
              ["value"] = MainGui.Two.Answer.TextBox.Text,
              ["inline"] = false
              },
          }
     }
}

Are you encoding it in JSON before you call :PostAsync()?

1 Like

Error 400 means that the issue is on your end. It could be due to you not encoding the message properly. Are you encoding it to JSON using HTTPService:JSONEncode() before-hand?

1 Like

Its not “contents” but “content” since that field is just a string.

Also if i remember correctly one of these are url keys are being used wrong

You can see a structure guide here Discord Webhook - Discord Webhooks Guide

1 Like

If it is even set to contents then the message should still be posted. I tested this myself and the text just doesn’t appear with setting it to contents. The issue is something completely different.

1 Like

Oh yeah the reason its erroring is because what i believe embeds field should be an array filled with embeds.

1 Like

That’s one issue. I’m currently testing it myself and it doesn’t work as well.

1 Like

There should also be another table inside of embeds as well.

2 Likes

Precisely what I was trying to point out :+1:

2 Likes

Try this:

local data3 = {
	["content"] = Mentions,
	["embeds"] = {{
		["title"] = Titles,
		["url"] = "https://www.roblox.com/users/"..UserID.."/profile",
		["color"] = 8856607,
		["thumbnail"] = {
			["url"] = PlayerPicture
		},
		["fields"] = {
			{
				["name"] = "**"..QuestionOne.."**",
				["value"] = AnswerOne,
				["inline"] = false
			},
			{
				["name"] = "**"..QuestionTwo.."**",
				["value"] = AnswerTwo,
				["inline"] = false
			},
		}
	}}
}

I think the issue is due to an invalid URL in the thumbnail and url field.

For the PlayerPicture, use this URL:
https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds=USERIDHERE&size=420x420&format=Png&isCircular=true

And replace the “USERIDHERE” text with your user ID and run a GetAsync on it. It would return a JSON table. After that, you can use JSONDecode to decode it and do response.data[1].imageURL for the players picture.

1 Like

Just saying, the field “url” does not exist in the main body of the message but it does exist inside of the embeds. The URL will appear as a masked link as Discord calls it and you will be able to click on the title text to go to the link.

1 Like

You’re right. I must’ve looked at it and didn’t think much about it. I’ll fix it.

1 Like

Unless you are using a proxy, you can’t send messages from Roblox servers to Discord (as discord blocks it).

Make sure you are using a proxy when firing the webhook otherwise it won’t work, regardless of how you format it.

1 Like

I’m using this:

HttpService:PostAsync(EthicsWebhook, HttpService:JSONEncode(Data))

Is this correct?

HttpService:PostAsync(EthicsWebhook, HttpService:JSONEncode(Data))

I fixed the “content” bit earlier and still received the error unfortunately.

What do you mean by the keys being used wrong as well? That is how they are coded in this person’s code which I tested and it worked for them: How do you make a discord webhook send an embed message?

I’m using a proxy so that’s not the issue.

Hey,
First off, its important not to use the default webhook directly. Instead, you should use a proxy, because in Studio, the standard Discord webhook API should work. Your JSON encoding seems correct, but if errors occur ingame, it might be because Discord doesnt allow Roblox to send webhooks directly. In that case, you should use a proxy like webhook.lewisakura.moe.
Additionally, Im unable to see what the player picture is it could be nil or something else causing errors. I recommend printing out the value to check. The same goes for the Titles variable try printing it as well to debug.

1 Like

This bit of data is inside of [embeds] = {} but when the message is sent to Discord, there is no thumbnail? What am I doing wrong here?

["thumbnail"] = {
["url"] = "https://www.roblox.com/headshot-thumbnail/image?userId="..UserID.."&width=420&height=420&format=png"
},

When I print out the PlayerPicture, I get this in the output:

This is not a URL and this asset is only valid for Roblox’s user not Discord. You should be using a proxy to send a get request to the Roblox APIs to get the actual avatar thumbnail URL. Here is how I would be getting the avatar thumbnail:

local thumbnailURL:string = "https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds=%s&size=150x150&format=Png&isCircular=false"

local function getThumbnail(player:Player)
	local userId:number = player.UserId
	local response:string = nil

	local success:boolean, errorMessage:string = pcall(function()
		response = HTTPService:GetAsync(thumbnailURL:format(userId))
	end)

	if not success then
		error(errorMessage)
	else
		return HTTPService:JSONDecode(response).data[1].imageUrl
	end
end
1 Like