Discord Webhook Embeds

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.

4 Likes

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.)

Either way, try removing the “s” from “embeds”.

1 Like

This game is not open to the public and this embed is only being passed for testing purposes.

The correct formatting according to the discord documentation is “embeds”, I’ve attempted passing embed with no positive change as well.

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.

Swapping the brackets won’t properly format a dictionary in lua.

I’ve been doing heavy JS for a few months. Don’t quite remember the Lua syntax.

I presume you know how to define a table inside of an array.

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?

Embeds expects an array. Regardless of if you’re passing one embed, it must be inside of an array.

1 Like

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.

The embeds field should look something like this iirc (on mobile, sorry).

[“embeds”] = {
    {
        [“title”] = “...”,
        ... etc
    }
}
5 Likes

Ah, I see. I should have read the documentation a bit closer.

I really appreciate your help!

2 Likes