Hello Devs, I am currently trying to make a report system in my game which uses Discord Webhooks but I’m facing a problem here.
I got my Server Script ready and all, but when I try execute the script, I get a HTTP 400 error which happens when I format something wrong.
This is the script:
local ls = game:GetService("LocalizationService")
local http = game:GetService("HttpService")
local player = game:GetService("Players").PlayerAdded:Wait()
local region = ls:GetCountryRegionForPlayerAsync(player)
local Countries = require(script.Countries)
local success, code = pcall(ls.GetCountryRegionForPlayerAsync, ls, player)
game.ReplicatedStorage.ColorChange.OnServerEvent:Connect(function()
if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Bug" then
player.PlayerGui.SettingsMenu.Report.Color.Value = 16730955
end
if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Other" then
player.PlayerGui.SettingsMenu.Report.Color.Value = 4960255
end
if player.PlayerGui.SettingsMenu.Report.DropdownSelect.Text == "Player" then
player.PlayerGui.SettingsMenu.Report.Color.Value = 4980555
end
end)
game.ReplicatedStorage.Report.OnServerEvent:Connect(function(player, report, dropdown)
local data = {
["embeds"] = {
["title"] = "Click to join Player server".." - "..dropdown,
["description"] = report,
["url"] = "roblox://experiences/start?placeId=13822889&gameInstanceId="..game.JobId.."",
["color"] = game.StarterGui.SettingsMenu.Report.Color.Value,
["fields"] = {
["name"] = "Sent Date:",
["value"] = ":flag_"..region..": "..Countries[code]..""
}
},
}
print(player.PlayerGui.SettingsMenu.Report.Color.Value)
print(Countries[code])
data = http:JSONEncode(data)
http:PostAsync("https://discord.com/api/webhooks/Webhook_link", data) -- line 38
end)
It’s likely this. If that is a Color3 value, it will return bad request with the embed because unlike discord bots with their appropriate modules, webhooks do not accept rgb or hexadecimal values. You need to give it the integer representation. For example, Color3 255, 170, 0 becomes 16755200.
I don’t mean to immediately shoot down other suggestions but I would just like to clarify on this. It seems discord has recently unblocked requests from roblox servers as I and many others are able to put the webhook URL directly in scripts and have it function correctly without the use of a proxy service. They were previously blocked, so just to clear up confusion for others also viewing this topic, it likely is not this.
it would also be HTTP 403 (Forbidden) if that were the case!
i was aware about the different color code, the …Color.Value is inside a playerGui
the numbers here are the integer values, im thinking that the server script probably cant see or edit the value inside the player’s gui
I don’t really understand the first point
if you check on this website, you can see that the fields thing can have two different “states”, one inline and one non inline
It’s basically adding each one as it’s own component.
For example, here using discord.js to send a message through a bot, you can see for embeds we need each value as it’s own array.
//ignore this bit
let embed = new EmbedBuilder()
.setTitle("Embed")
.setDescription("Description")
.setColor(0xff8500)
//this is the bit you need to notice
.addFields(
//notice here how each field is it's own dictionary. They are seperate
{name: "field", value: "value", inline: true},
{name: "field2", value: "value2", inline: true}
)
channel.send({embeds: [embed]})
This contradicts to your code, where the fields dictionary is being used by your field, and does not contain a set of fields.
Try to format your field like this:
["fields"] = {
--nested dictionary for the field
{
["name"] = "Sent Date:",
["value"] = --etc with the country flag data
}
}
Oh, wait. You know how I mentioned a nested table for each field element? I think you need to encase that entire embed in a table as well because of the same issue.