Report system from Roblox to Discord

Hey,

I want to create a reporting system.

First, the player enters the player’s name and the reason for the report. When everything is ready, the player presses the submit button, and the report should be sent to my Discord server through a webhook, posting the player’s report message from Roblox to my Discord server’s report channel. The problem I’m facing is this error message:

Cannot Send Report: Reason Unable to cast Dictionary to bool

Here is the code:

local WebhookUrl = "https://discord.com/api/webhooks/11..." --I don't want to show my webhook's URL..

local playerNameTextBox = script.Parent:FindFirstChild("playername")
local reasonTextBox = script.Parent:FindFirstChild("reason")
local sendButton = script.Parent:FindFirstChild("submit")

sendButton.MouseButton1Click:Connect(function()
	local playerName = playerNameTextBox.Text
	local reason = reasonTextBox.Text

	if playerName ~= "" and reason ~= "" then
		local message = string.format("Player %s reports: %s", playerName, reason)

		local data = {
			content = message
		}

		local headers = {
			["Content-Type"] = "application/json"
		}

		local success, response = pcall(function()
			return game:GetService("HttpService"):PostAsync(WebhookUrl, game:GetService("HttpService"):JSONEncode(data), Enum.HttpContentType.ApplicationJson, headers)
		end)

		if success then
			if response == "ok" then
				print("Report sended successfully")
				
			else
				warn("Cannot send report: Error " .. response)
			end
		else
			warn("Cannot Send Report: Reason " .. response)
		end
	else
		warn("You must put player's name and reason")
	end
end)

Thank you for your time!

6 Likes

Maybe delete the return?

1 Like

Try checking what success & response gives you back?

2 Likes

I cannot check what ‘response’ gives me because ‘success’ doesn’t occur and gives the error “Cannot Send Report: Reason Unable to cast Dictionary to bool”

1 Like

You are using this method incorrectly! There’s a boolean argument you missed.

That’s from the else block. Have you tried printing them both?

STOP! THIS IS NOT SERVER SITE !!!Any hacker can get your webhook URL super easy, shared it, changed the script, send inappropriate content to the server, spam the channal so that the webhook is blocked from dc and so much more!!!Use remoteevents with cooldowns and server scripts!!!

You’re not able to send HTTP requests on the client

This line in your code seems to be the issue, you’re missing the compress field

Instead you should use this:

return game:GetService("HttpService"):PostAsync(WebhookUrl, game:GetService("HttpService"):JSONEncode(data), Enum.HttpContentType.ApplicationJson, false, headers)

However you can probably just remove the headers because you’ve set Enum.HttpContentType.ApplicationJson, so a better approch would be this:

return game:GetService("HttpService"):PostAsync(WebhookUrl, game:GetService("HttpService"):JSONEncode(data), Enum.HttpContentType.ApplicationJson)

Also note, Discord blocks HTTP requests from Roblox game servers, so you’ll have to use a proxy such as https://webhook.lewisakura.moe/ to make it work in game.

It seems you are trying to use your webhook in a localscript. This is bad because it won’t work (HTTP request can only be sent from the server), and exploits could steal your webhook URL and use it

1 Like

I assume it is because he’s connecting it to a button event.

I agree

You should also send a RemoteEvent to the server whenever a player presses the button. You cannot send HTTP requests from the client.

That’s the problem, and the hacker has the webhock url and can do on your disvord server what I already meant. There are also other platforms… Therefore serverscript with remoteevents and countdown. More precisely I already said it…

you should use an embed, you wouldnt want to wake up with 170 notifications wouldnt you?
image

I will do remote-event system but the problem is, how can I keep my webhoock’s URL safe? One person said that I should make a configuration file but i don’t know, how and how it works? I can’t put the url itself into the code because it’s really easy to find the url from there.

If it is on the server it is safe. Also, roblox has announced that they will introduce secrets.

Players cannot see inside server scripts.