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

Working with discord web hooks?

Hey I am trying to work with discord Web hooks this is my attempt local url = "" local http = game:GetService("HttpService")

game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) local data = {['username'] = player.Name, ['content'] = msg } local newdata = http:JSONDecode(data) http:PostAsync(url,newdata) end) end)




I get this error  "Unable to cast value to std::string"

and also I have a bad rep because I was being lazy a while ago so please if you think this question is good if you can help me and push the up reputation please :)

1 answer

JSONDecode turns a json string into a table. What you want to use is JSONEncode which turns a table into a json string.

Also, because discord blocked roblox's useragent from using webhooks, you're going to need a proxy such as discord.osyr.is

local url = "https://discord.osyr.is/api/webhooks/452278298781810699/noBTJK779MnmNuc9auhDQFp3-WMwuD83JQQyjjgM56S8zx8JoVsnVavrJy9e4XBjKdRP"
local http = game:GetService("HttpService")

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		local data = {
			['username'] = player.Name,
			['content'] = msg
		}
		local newdata = http:JSONEncode(data)
		http:PostAsync(url,newdata)
	end)
end)

Btw, exposing your full webhook url to the public is a bad idea.

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