Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Working with discord web hooks?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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.

Ad

Answer this question