I’ve been working on a discord webhook system, but I am struggling when posting the webhook to the URL.
It seems that I am getting http 400 errors whenever trying to post to discord, I have searched but none of the results fix my problem. I assume I am formatting something incorrectly. Here is what I have:
local webhookURL = "nolol"
local payload = {
content = "New Data Issue:",
embeds = { {
title = "Data Error",
description = "A new data error has been detected for the following user: /n /n"..player.UserId,
color = 16734296,
fields = { {
name = "Error Message",
value = err
}, {
name = "Current Data",
value = _G.dataTable
} },
author = {
name = player.Name
}
} }
}
local json = HttpService:JSONEncode(payload)
HttpService:PostAsync(webhookURL, json, Enum.HttpContentType.ApplicationJson)
Am I doing something incorrectly? Am I not formatting this right? I think I may have oversaw something so it’s probably pretty simple, I would like some help finding it though.
Interesting. I know that the raw JSON is supposed to look like this:
{
"content": "New Data Issue:",
"embeds": [
{
"title": "Data Error",
"description": "A new data error has been detected for the following user:\n\n$username",
"color": 16734296,
"fields": [
{
"name": "Error Message",
"value": "$error"
},
{
"name": "Current Data",
"value": "$data"
}
],
"author": {
"name": "$username"
}
}
]
}
That could be why, you cannot send tables to Discord to post in an embed, strings only.
You’ll need to either delete that field or use JSONEncode to change the table to a string (essentially).
The max amount of characters you can have in a field value is 1024, and if you exceed that, or in your case provide a non-string, you will get 400 Bad Request.