Strange error with HTTP service

  1. What do you want to achieve? I want to do a suggestion GUI

  2. What is the issue? Basically if i write the suggestion on roblox studio it works as you can see
    image
    image (Discord)

BUT

in game it doesn’t work and it gives me this strange error when i click “Submit”

My scripts if you are interested

CLIENT

local Player = game.Players.LocalPlayer
local ToggleButton = script.Parent.ToggleButton
local SuggestionFrame = script.Parent.SuggestionFrame
local SuggestionBox = SuggestionFrame.SuggestionBox
local SubmitButton = SuggestionFrame.SubmitButton


ToggleButton.MouseButton1Click:Connect(function()
	if SuggestionFrame.Visible == true then
		SuggestionFrame.Visible = false
	else
		SuggestionFrame.Visible = true
	end
end)

SubmitButton.MouseButton1Click:Connect(function()
	local Suggestion = SuggestionBox.Text
	game.ReplicatedStorage.Suggest:FireServer(Suggestion) --I'M SURE THAT THE REMOTE EVENT IS IN REPLICATEDSTORAGE
end)

SERVER

local HttpService = game:GetService("HttpService")
local WebhookURL = "https://discordapp.com/api/webhooks....... 

local function postToDS(Message)
	local Data = {
		["content"] = Message
	}
	Data = HttpService:JSONEncode(Data)
	HttpService:PostAsync(WebhookURL, Data)
end

game.ReplicatedStorage.Suggest.OnServerEvent:Connect(function(Player, Suggestion)
	postToDS("Suggestion from " .. Player.Name .. ": " .. Suggestion)

end)
1 Like

If this is a team create game, you need to commit your script. If that doesn’t work, copy the script, close the game, and re-open it, then paste the script in.

2 Likes

Ty For the answer

This is not a team-create game (nobody join the game in studio for now except me), but i don’t really understand what have i got to do. Can you explain it please?

I’m not sure what the problem is, I can’t see anything wrong with the code itself but if I had to guess I’d say that there’s a " somewhere in the webhook closing the string, as I can’t find a single lowercase s in your script that would cause any issues. The only thing I can say is to use WaitForChild when declaring ToggleButton, SuggestionFrame, etc. The reason I asked you to close the game and re-open it is because sometimes with slow networks you can be disconnected with studio where your changes are not properly implemented when you press the play button. I’ve had it happen to me acouple of times.

1 Like

image
Now it is giving me another problem

You have to run the webhook through a proxy, Roblox is blacklisted by discord. All you have to do is make a replit JS, require express and on POST take the data from the body and send it to the Discord URL using a networking library like Axios.

1 Like

can it help me?

ROBLOX Blocks the Discord API. You need to use an Valid Proxy server.

1 Like

No I don’t think so, It’s best to maintain your own middleware anyways so if it goes down you’re able to fix it. You also run the risk of your webhook URL being logged using public proxies, which isn’t really the greatest position to be in. Making a proxy really isn’t all that difficult, if you can’t figure it out I’ll link a replit project that you can just clone.

1 Like

image
With this WebhookURL it works, but i don’t want to make it a risk.

Making a proxy really isn’t all that difficult

I don’t know what is a proxy and if you can link me a replit project it would help me a lot. But you have to say me how to use it or maybe i will serach a tutorial online

Warning: Hyra Hooks will be shutdown for free usage by tomorrow. Check the hyra hook Dev-Forum post for more information.

1 Like

This is incorrect as it is the exact contrary.

1 Like

You are wrong.

Please research before you post.

1 Like

I am not wrong. According to you roblox blocks the discord api while it is discord to block requests from roblox due to users abusing webhooks for logging

1 Like

But then why does the Discord Web Hook work in Studio but not in the actual live experience?

How should Discord know that the request comes from Studio or Live Experience?

1 Like

Because in studio your requests don’t use the roblox user agent while in live servers they do.

1 Like

Let me confirm that. I am sorry if I was wrong.

But my guess is that this is not the case since that would be a vulnerability for malicious plugins/free models.

1 Like

Plugins run in studio so their requests will be seen by discord as legitimate requests not coming from roblox as they are made on your local machine, in fact they can interact with the discord webhooks api

Sorry, my laptop died while writing the proxy. I’m back home now so I’ll get on making the replit. Will reply when done.

1 Like

Anyways, it ended up being shorter than I expected, so I’ll just post it here for future reference.
If you’re wondering how to use it, I’ll explain it.

Steps

Step 1: Sign up for replit. You can use github, or any other of the many ways they allow you to.

Step 2: Create a NodeJS replit.

Step 3: Navigate to the “Secrets” tab and create a new secret using the key “webhook” with your webhook link as the value.

Step 4: Make a new file called “index.js”, and paste the server code in.

Step 5: Press run, and copy the URL that shows up on the pseudo-browser on the right.

EDIT: You might have to install the dependencies too. Not hard, just go to the packager and
install express and axios.

Step 6: POST to the copied URL.

Step 7: profit

Server code:

const wh = process.env.webhook;
const express = require("express");
const server = express();
const axios = require("axios");
const fs = require("fs");
server.use(express.json());
server.post("/",(req,res)=>{
	console.log(req.body);
	axios.post(wh,req.body).then(resp=>{
		res.sendStatus(400);
	}).catch(err=>{res.send(err)});

})
server.get("/",(req,res)=>{ res.sendStatus(401) });
server.listen(1880,()=>{});

Example Lua code:

local HttpService = game:GetService("HttpService")

local HttpData = HttpService:JSONEncode({
	content = "this is a test"
})

local res = HttpService:PostAsync("your proxy link here",HttpData,Enum.HttpContentType.ApplicationJson)
print(res) -- Should print 400 OK or the error the proxy encountered.

If there’s anything wrong, feel free to let me know and I’ll help you resolve it.

1 Like