Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Webhook isn't working at all, no errors appearing in console?

Basically, I'm trying to make a webhook that will send all messages being sent in my roblox game to a channel in my discord server

(you may think this would be API abuse but I don't plan to have any more than 10 people in the game at once)

I think the problem could be the variables, but I'm not entirely sure, I'm a bit of a noobie with API.

**The code: **

game.Players:FindFirstChild().Chatted:Connect(function(msg)
	local text = msg
	local user = game.Players.LocalPlayer.Name
local http = game:GetService("HttpService")
local Data = {
	["content"] = "`"..text.."`",
	["username"] = user,
}

Data = http:JSONEncode(Data)

http:PostAsync("*webhook link redacted.*", Data) 
end)

8 comments

0

is HttpEnabled set to true?

0

yes, it is

0

I'm not familiar with discord's API, but are you certain that they use JSON and not some other format?

0

To me, that code looks fine, my guess is something on the other end is wrong.

0

im pretty sure they use json

0

Ok, well in the [REDACTED] webhook link, do they give you a custom webhook link or is it some generic one with a key they give you?

0

its a generic one thats given to me, i could send you the link if you got discord, my tag is Koyoka#2464

1 answer

✓ Accepted answer

There was nothing wrong with any of the http stuff, just a simple mistake with finding the first player, and also no getting a LocalPlayer from a server script:

game.Players.ChildAdded:Wait()
local player = game.Players:FindFirstChildOfClass("Player")
player.Chatted:Connect(function(msg)
    local text = msg
    local user = player.Name
	local http = game:GetService("HttpService")
	local Data = {
    	["content"] = "`"..text.."`",
    	["username"] = user,
	}
	Data = http:JSONEncode(Data)
	http:PostAsync("", Data) --Put the link you saved between the two quotes.
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.