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

I need a bit more help with Discord webhooks and JSON, can anyone assist?

Hi there.

I previously asked how I'd fix a problem, and someone told me to use raw json. I did that, but now I can't use variables, and they are essential to my code. Also, if I encode the JSON, I can't embed. So I'm stuck in an either or.

Recommended code:

local message = [[{
    "username":"hi",
    "content": "yo",
    "embeds": [{
        "description": "hii", 
        "title": "hiii", 
        "fields":[
        {"name":"hiiii", "value":"hiiiii"}, 
        {"name":"hiiiiii", "value":"hiiiiiii"}
        ]
    }]
}]]
game:GetService('HttpService'):PostAsync("webhook.com", message, Enum.HttpContentType.ApplicationJson)

OK, and then I tried this: ``{"name":"Quick user link:","value":..UL1..UL1B..UL2},

and it gave me a HTTP 404 Bad Request.

I'd like to be able to use these variables since standard messages just dont cut it for error reporting.

Thanks for the guy who helped me, but now I need this problem

Any help would be greatly apprechiated!

Thanks.

1 answer

✓ Accepted answer

How I send data over is like this, I use the JSONEncode function of HttpService to turn a table into a json string that can be sent and used on my web server

game.HttpService:JSONEncode({"connect",data,plr.Name,plr.UserId})

Example

local response = game.HttpService:PostAsync("http://example.com",game.HttpService:JSONEncode({"connect",data,plr.Name,plr.UserId}))

Also if you were to use your recommended string you could use Concatenation to put in stuff from variables or things like that

local message = [[{
    "username":"]]..plr.Name[[..",
    "content": "]]..data.StringContent.Value..[[",
    "embeds": [{
        "description": "hii", 
        "title": "hiii", 
        "fields":[
        {"name":"hiiii", "value":"hiiiii"}, 
        {"name":"hiiiiii", "value":"hiiiiiii"}
        ]
    }]
}]]

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