HTTP 400 (Bad request)

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

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to create a host system, but I keep getting the HTTP 400 error when I try to send the passers to discord.
game.ReplicatedStorage.Session.OnClientEvent:Connect(function(Mode, Host)

	local passers = function()
		for _,v in pairs(game.Players:GetChildren()) do
			if v.Status == "Passed" then
				return true
			else
				return false
			end
		end
	end

	if Mode == "Start" then

		script.Parent.Visible = true
		script.Parent.Text = "Welcome to today's session! My name is "..tostring(Host)..", I will be your host for today."
		wait(5)
		script.Parent.Text = "I am assisted by my Co-Host."
		wait(2.5)
		script.Parent.Text = "I will now go over some rules for today's interview session."
		wait(5)
		script.Parent.Text = "1. Do not troll, caps abuse, or spam."
		wait(2.5)
		script.Parent.Text = "2. Always listen to you trainer, and the hosts."
		wait(2.5)
		script.Parent.Text = "3. Do not speak without requesting PTS, or being asked a question."
		wait(5)
		script.Parent.Text = "4. Do not try to disturb others, and do not cheat. We have chat logs to prevent this."
		wait(5.5)
		script.Parent.Text = "5. Always follow these rules. Failure to do so, will result in punishment."
		wait(4.5)
		script.Parent.Text = "We will now begin, please wait for an interviewer to call your name."
		wait(4)
		script.Parent.Visible = false
	elseif Mode == "End" then
		script.Parent.Visible = true
		script.Parent.Text = "This interview session is now coming to an end."
		wait(3.5)
		script.Parent.Text = "Thank you for attending."
		wait(2)
		script.Parent.Text = "The failed people will now be kicked."
		for _,v in pairs(game.Players:GetChildren()) do
			if v.Status == "Failed" then
				v:Kick("Sorry, but you have failed this session!\nPlease do not feel discouraged as you can always try again!")
			end
		end
		wait(2.5)
		script.Parent.Text = "Congrats! If you are seeing this message, that means that you passed!"
		wait(5)
		script.Parent.Text = "Please wait as I log the passers!"
		game.ReplicatedStorage.SendtoDiscord:FireServer("Passers:\n"..tostring(passers()))
	end
end)

Btw, after this is complete, it will be released to the public. :smiley:

The request code on the server might be more helpful than the client code :slight_smile:

1 Like

More than that, this should almost be a server script itself. He is trying to manage multiple players from a local script, which isn’t possible.

What exactly is “Status”? Is it a ValueObject?

This code is not complete - please as requested before add your Server code (however remove your webhook URL before you post it, or other people may be able to use it!)

I also think that I should add it works if I make it only a string. but when I try to add arguments, it doesn’t work.

Here is the server code. (The one that sends the webhook)

game.ReplicatedStorage.SendtoDiscord.OnServerEvent:Connect(function(content)
	local http = game:GetService("HttpService")
	local Data = {
		["content"] = content
	}

	Data = http:JSONEncode(Data)

	http:PostAsync("", Data)
end)

Your request is blank. I assume because you don’t want to share your request for privacy reasons.

So… I don’t know what to tell ya. A 404 request means that your request is wrong somehow. Read the discord docs.

its not 404- Its 400…
And if you can’t help don’t post. :frowning:

The first argument of OnServerEvent is the player who fired the remote

No, it goes Mode, Player.

Random words here to bypass the message minimum filter.

What do you mean no

game.ReplicatedStorage.SendtoDiscord.OnServerEvent:Connect(function(caller, content)

that’s not how I use it. and it doesn’t have to be like that.
I just need to know why whenever I add the arguments (the people who passed) it doest work.
But if I don’t add the people who passed, it works.

It’s not gonna work if you don’t do it like that… The player argument is automatically passed, you can’t control it

1 Like

???

so what do I do??

Add the player argument in your OnServerEvent function

game.ReplicatedStorage.SendtoDiscord.OnServerEvent:Connect(function(caller, content)

K.
I will try this.

Random words here to bypass the minimum character filter.

It worked!

But something is still wrong…
It logged “False”
Screen Shot 2021-04-12 at 10.22.24 AM

Because you return true or false in your passers function.

If you want to get a table of all people that passed you should do something like this:

local passers = function()
	local passers = {}
	for _,v in pairs(game.Players:GetChildren()) do
		if v.Status == "Passed" then
			table.insert(passers, v.Name)
		end
	end
	return passers
end

And then when you fire the remote it should be something like:

game.ReplicatedStorage.SendtoDiscord:FireServer("Passers:\n" .. table.concat(passers(), ", "))

Two issues I see, one… change OnServerEvent:Connect(function(content) to OnServerEvent:Connect(function(player,content)… the first value will always be the Player who sent the request value.

Next, add wait(0.05) above local http = game:GetService("HttpService"). This prevents the HTTPs Request from being overly spent, just a tip I learned a little while ago.

Third, there needs to be a link for the webhook to post somewhere. So, may a value called local WebhookURL = "WebhookLinkHere".

After that, change http:PostAsync("", Data) to http:PostAsync(WebhookURL, Data)

Tell me what the results are after testing please.

It doesn’t work.
It just logged “Passers:”
It didn’t actually log them which is weird because we returned the passers.