HttpService:PostAsync HTTP 400 (Bad Request)

Hello so what is really weird about this is that it worked before but suddenly stopped working, i didn’t even touch the script and it suddenly broke over night. Don’t know what is wrong

local webhookURL = "https://ptb.discord.com/api/webhooks/819931920254763018/bms1YBmwnDOXuu54m5BrhuRyCK5NKnW6fazquBDE1j-2ieBaeXQ2jqyarQSrvTFDAbB5"
local httpService = game:GetService("HttpService")
local remote = game.ReplicatedStorage.Remotes.Moderation
local plrs = game:GetService("Players")

remote.OnServerEvent:Connect(function(plr,name,punish,lenght,desc)
	if plr:GetRankInGroup(2766605) >= 160 then
		local contentHs, isReady2 = plrs:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		if punish == "kick" and game.Players:FindFirstChild(name) then
			print("kick")
			local contentBs, isReady = plrs:GetUserThumbnailAsync(plrs:FindFirstChild(name).UserId, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
			local data = {
				['embeds'] = {{
					['title'] = "Sent in Area-14",
					['description'] = "**User:** ["..name.."](https://www.roblox.com/users/"..plrs:FindFirstChild(name).UserId.."/profile) was kicked",
					['color'] = 255,
					["url"] = "https://www.roblox.com/games/706231710/SCP-Area-14-ROLEPLAY?refPageId=9d49c0b7-3239-408b-8ced-4793e59d1192",
					["footer"] = {
						["icon_url"] = "https://upload.wikimedia.org/wikipedia/en/thumb/0/0a/Logo_of_the_SCP_Foundation.png/1024px-Logo_of_the_SCP_Foundation.png",
						["text"] = "Moderation Bot V.1.1"
					},
					["thumbnail"] = {
						["url"] = contentBs
					},
					["author"] = {
						["name"] = "Report by "..plr.Name.."",
						["url"] = "https://www.roblox.com/users/"..plr.UserId.."/profile",
						["icon_url"] = contentHs
					},
					["fields"] = {
						{
							["name"] = "Reason:",
							["value"] =  desc
						}
					}
				}}
			}
			game.Players:FindFirstChild(name):Kick(desc)
			local finalData = httpService:JSONEncode(data)
			httpService:PostAsync(webhookURL, finalData)
		elseif punish == "ban" then
			print("ban")
			if plrs:FindFirstChild(name) then
				local contentBs, isReady = plrs:GetUserThumbnailAsync(plrs:FindFirstChild(name).UserId, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
				local data = {
					['embeds'] = {{
						['title'] = "Sent in Area-14",
						['description'] = "**User:** ["..name.."](https://www.roblox.com/users/"..plrs:FindFirstChild(name).UserId.."/profile) was banned for "..lenght,
						['color'] = 16121868,
						["url"] = "https://www.roblox.com/games/706231710/SCP-Area-14-ROLEPLAY?refPageId=9d49c0b7-3239-408b-8ced-4793e59d1192",
						["footer"] = {
							["icon_url"] = "https://upload.wikimedia.org/wikipedia/en/thumb/0/0a/Logo_of_the_SCP_Foundation.png/1024px-Logo_of_the_SCP_Foundation.png",
							["text"] = "Moderation Bot V.1.1"
						},
						["thumbnail"] = {
							["url"] = contentBs
						},
						["author"] = {
							["name"] = "Report by "..plr.Name.."",
							["url"] = "https://www.roblox.com/users/"..plr.UserId.."/profile",
							["icon_url"] = contentHs
						},
						["fields"] = {
							{
								["name"] = "Reason:",
								["value"] =  desc
							}
						}
					}}
				}
				local finalData = httpService:JSONEncode(data)
				httpService:PostAsync(webhookURL, finalData)
			else
				local data = {
					['embeds'] = {{
						['title'] = "Sent in Area-14",
						['description'] = "**User:** ["..name.."](https://www.youtube.com/watch?v=GwF9EjnsNUQ) was banned for "..lenght,
						['color'] = 16121868,
						["url"] = "https://www.roblox.com/games/706231710/SCP-Area-14-ROLEPLAY?refPageId=9d49c0b7-3239-408b-8ced-4793e59d1192",
						["footer"] = {
							["icon_url"] = "https://upload.wikimedia.org/wikipedia/en/thumb/0/0a/Logo_of_the_SCP_Foundation.png/1024px-Logo_of_the_SCP_Foundation.png",
							["text"] = "Moderation Bot V.1.1"
						},
						["thumbnail"] = {
							["url"] = "https://tr.rbxcdn.com/8ff6d72546ed6077897954d6bc158596/420/420/Decal/Png"
						},
						["author"] = {
							["name"] = "Report by "..plr.Name.."",
							["url"] = "https://www.roblox.com/users/"..plr.UserId.."/profile",
							["icon_url"] = contentHs
						},
						["fields"] = {
							{
								["name"] = "Reason:",
								["value"] =  desc
							}
						}
					}}
				}
				local finalData = httpService:JSONEncode(data)
				httpService:PostAsync(webhookURL, finalData)
			end
		elseif punish == "arrest" and game.Players:FindFirstChild(name) then
			print("arrest")
			local contentBs, isReady = plrs:GetUserThumbnailAsync(plrs:FindFirstChild(name).UserId, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
			local data = {
				['embeds'] = {{
					['title'] = "Sent in Area-14",
					['description'] = "**User:** ["..name.."](https://www.roblox.com/users/"..plrs:FindFirstChild(name).UserId.."/profile) was arrested for 5 minutes",
					['color'] = 16122111,
					["url"] = "https://www.roblox.com/games/706231710/SCP-Area-14-ROLEPLAY?refPageId=9d49c0b7-3239-408b-8ced-4793e59d1192",
					["footer"] = {
						["icon_url"] = "https://upload.wikimedia.org/wikipedia/en/thumb/0/0a/Logo_of_the_SCP_Foundation.png/1024px-Logo_of_the_SCP_Foundation.png",
						["text"] = "Moderation Bot V.1.1"
					},
					["thumbnail"] = {
						["url"] = contentBs
					},
					["author"] = {
						["name"] = "Report by "..plr.Name.."",
						["url"] = "https://www.roblox.com/users/"..plr.UserId.."/profile",
						["icon_url"] = contentHs
					},
					["fields"] = {
						{
							["name"] = "Reason:",
							["value"] =  desc
						}
					}
				}}
			}
			game.Players:FindFirstChild(name).Team = game.Teams.Arrested
			game.Players:FindFirstChild(name).Character:FindFirstChild("Humanoid").Health = 0
			local finalData = httpService:JSONEncode(data)
			httpService:PostAsync(webhookURL, finalData)
			wait(120)
			game.Players:FindFirstChild(name).Team = game.Teams["Class-D Personnel"]
			game.Players:FindFirstChild(name).Character:FindFirstChild("Humanoid").Health = 0
		elseif punish == "GUI" then
			if name ~= "" then
				plr.Character:FindFirstChild("NameGUI").Username.Text = name
				if lenght == "true" then
					for i,v in pairs (plr.Character:FindFirstChild("NameGUI"):GetChildren()) do
						if v then
							v.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
						end
					end
				else
					for i,v in pairs (plr.Character:FindFirstChild("NameGUI"):GetChildren()) do
						if v then
							v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
						end
					end
				end
			else
				plr.Character:FindFirstChild("NameGUI").Username.Text = plr.Name
				if lenght == "true" then
					for i,v in pairs (plr.Character:FindFirstChild("NameGUI"):GetChildren()) do
						if v then
							v.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
						end
					end
				else
					for i,v in pairs (plr.Character:FindFirstChild("NameGUI"):GetChildren()) do
						if v then
							v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
						end
					end
				end
			end
		end
	end
end)

Have you activated HTTP requests?

Oh wait, you’re getting an error because of ptb.discord.com in your webhookURL,
all you have to do is remove the ptb.

1 Like

you shouldn’t show your webhook url to everyone

the problem is that he used some keys like “url” that there are nowhere into discord API docs EDIT : watch Discord Developer Portal — Documentation — Channel

what doo you want to do with ["url"] = "https://www.roblox.com/games/706231710/SCP-Area-14-ROLEPLAY?refPageId=9d49c0b7-3239-408b-8ced-4793e59d1192"

GetUserThumbnailAsync is most likely the problem. I explained this in another post:

The link you would need to use for the avatar thumbnail is https://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userid={userId}

image

Also you shouldn’t be exposing your webhook url because anyone can post whatever they want to it without any authentication. You should probably generate a new webhook before someone does something bad with the old one.

1 Like