HTTP 400 Bad Request Discord Webhook

Hello !
I have a problem, I can’t use my webhook, why ?

function exploiter(player)
	local HS = game:GetService("HttpService")
	local WebhookURL = -- Here is my webhook url
	local userId = player.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content  = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
	local MessageData = {
		["content"] = player.Name.. " is suspected of cheating",
		["avatar_url"] =  content
	}

	MessageData = HS:JSONEncode(MessageData)
	
	HS:PostAsync(WebhookURL,MessageData)
end

Thank you for helping me

What is the problem? Are you getting errors in the output? Are you not receiving the result in your webhook?

When and where is exploiter called?

1 Like

I think you may need to get the avatar url from one of roblox’s apis instead of GetUserThumbnailAsync, as the latter returns a rbxthumb:// url, usable on Roblox only, try changing your code around to this?

local HS = game:GetService("HttpService")
function exploiter(player)
	local WebhookURL = -- Here is my webhook url
	local userId = tostring(player.UserId)
	
	local success, content = pcall(HS.GetAsync,HS,"http://thumbnails.rprxy.xyz/v1/users/avatar-headshot?format=Png&isCircular=true&size=420x420&userIds="..userId)
	
	local MessageData = {
		["content"] = player.Name.. " is suspected of cheating",
	}
	
	if success then
		MessageData["avatar_url"] = HS:JSONDecode(content).data.imageUrl
	else
		warn(content)
	end
	
	Data = HS:JSONEncode(MessageData)
	
	HS:PostAsync(WebhookURL,Data)
end

This is so if it couldn’t get the image it’ll warn you the error given, outside, add avatar_url to your dictionary and fire it off

More info:

And if at the end it doesn’t work, is HTTP Enabled or disabled?

1 Like

Hi there! Are there any errors in the output window?

1 Like

Thank you now it work !
But as I am curious, what does mean this lines of codes ?

local success, content = pcall(HS.GetAsync,HS,"http://thumbnails.rprxy.xyz/v1/users/avatar-headshot?format=Png&isCircular=true&size=420x420&userIds="..userId)
	
	local MessageData = {
		["content"] = player.Name.. " is suspected of cheating",
	}
	
	if success then
		MessageData["avatar_url"] = HS:JSONDecode(content).data.imageUrl
	else
		warn(content)
	end

What is pcall and why not lets normal roblox error ?
Does it send the webhook even if the avatar don’t work ?

Basically what I did was use GetAsync to retrieve the icon of the user with the specified userid, I placed it in a pcall so if it errors, it’ll still send the webhook but without an avatar url, but if it worked, it’ll sned it with the avatar url.

If I didn’t put the pcall, if it errored, it would break the entire script. Although now taht I realise, if it errors it would send a different json file, so I think it should be changed around

Edit: I think this would be better

local HS = game:GetService("HttpService")
function exploiter(player)
	local WebhookURL = -- Here is my webhook url
	local userId = tostring(player.UserId)
	
	local content = HS:GetAsync("http://thumbnails.rprxy.xyz/v1/users/avatar-headshot?format=Png&isCircular=true&size=420x420&userIds="..userId)
	content = HS:JSONDecode(content)
	
	local MessageData = {
		["content"] = player.Name.. " is suspected of cheating",
	}
	
	if content.data and content.data.imageUrl then
		MessageData["avatar_url"] = content.data.imageUrl
	end
	
	Data = HS:JSONEncode(MessageData)
	
	HS:PostAsync(WebhookURL,Data)
end

Checks if there’s a data key in the dictionary and if that data key has an imageUrl key

Why do you get the request async and not sync ?
And what happens if you don’t decode content ?

You need to do GetAsync as that’s the name of the function, it yields/waits until the request has been given or error

Usually anything returend by GetAsync is a JSON file that needs to be converted into an lua dictionary, it would error if you don’t decode it because you’d try to get dictionary keys from a string

Well my webhook don’t have avatar now :confused: