I have been trying to send an embed to a discord server via webhook, but the embed either isn’t formatted correctly, or there is an error/constraint stopping the request from posting.
hookURL = "https://discord.osyr.is/api/webhooks/" --removed for post
httpService = game:GetService("HttpService")
function newPlayer(Player)
local data = {
["embeds"] = {
["title"] = "Neophyte Ascension Center",
["description"] = "[" .. Player.Name .. "](http://www.roblox.com/users/" .. tostring(Player.userId) .. "/profile) has joined.",
["color"] = 16766976
}
}
local enData = httpService:JSONEncode(data)
httpService:PostAsync(hookURL,enData)
end
game.Players.PlayerAdded:Connect(newPlayer)
I’ve tried several different formats for the embed, but none seem to work.
You shouldn’t be using Discord for logging. Especially not such a high volume logging function such as this, if I’m guessing correctly. Your webhook / server are liable to be removed if you continually hit rate limits, which you absolutely will if you run this for every player join in a busy game. (IIRC logging is also against Discord TOS.)
Weird. I remember seeing “embed” somewhere in the docs.
The embeds field expects an array of objects. Try replacing the curly braces on the embeds field with square brackets and wrap your embed inside in curly braces. My brain is JS.
The format posted is correct for creating a lua dictionary. The Embeds field expects an object for each embed, which I’m only passing one (hence the single dictionary).
Could there be an issue JSONEncoding the lua dictionary?
The embed is in the “data” array. That entire array, which includes the embeds array and dictionary is getting JSONEncoded and Posted, but doesn’t end up posting in the discord server.
If my code isn’t in an array, could you reorganize and post the correct code, because I don’t see what I’m doing wrong at this point.