Discord web hook images not working and colors

I was making a web hook that sends a message every time someone joins and I don’t know how to get the colors right. If someone can tell me. Also how do you get images to work in here

function webhookService:createEmbed(url, title, message, image)
	local data = {
		['content'] = "",
		['embeds'] = {{
			["image"] = {["url"] = image},
			['title'] = "**"..title.."**",
			['description'] = message,
			['type'] = "rich",
			["color"] = tonumber(3769131) -- I need that to change
		}}
	}
	local finalData = https:JSONEncode(data)
	https:PostAsync(url, finalData)
end
2 Likes

I recommend you check out a website like https://discohook.org/ and create a dummy embed there, then convert it to Lua.

3 Likes

Ok I will try it and also how do you convert it to lua

1 Like

Well, once you create your embed, you can just click on the “JSON Data Editor” button. There, it will show the JSON of that embed. You can simply copy the color code (no need to do tonumber() if I am correct) and paste it into the color. For images, just look at the structure and copy it over (although your current structure seems to work, if the image variable is an image URL).

1 Like

Ok thanks I was going to put a avatar head shot in the message I dont know if its possible

1 Like

It is most definitely possible, although I recommend the use of a thumbnail instead of an image for that. I did make a similar webhook for when someone joins. Here is the code that I used for that:

Players.PlayerAdded:connect(function(Plr)

	local Message = ""
	
	local Embeds = {
		{
			title = "Game: **"..game.Name.."**",
			description = "----------------",
			url = "https://www.roblox.com/games/"..game.GameId,
			color = 0x33cc33,
			thumbnail = {url="https://www.roblox.com/headshot-thumbnail/image?userId="..Plr.UserId.."&width=420&height=420&format=png"},
			fields = {
				{name = "**Player Joined:**" , value = Plr.Name..":"..Plr.UserId},
			},
		}
	}
	
	SendMessage(Webhook, Message, Embeds) -- This basically just invoked the webhook

end)

Also, you do not need to have the content in there as a webhook is enough if I am correct. This will also prevent your message from having a weird gap and looking unnatural. Try it and see if it works normally, and once it is working, remove the ['content'] = "", line and try that one. Hopefully this helped you.

1 Like

Ok thanks and what is send message it erroring out for me

SendMessage was a function that basically fired the webhook. No need to copy my structure, I just put it there so you can get inspiration. More specifically, I wanted to show you the thumbnail structure. If you set the URL to https://www.roblox.com/headshot-thumbnail/image?userId=USER_ID&width=420&height=420&format=png (with USER_ID being the ID of the user), it will give you a little headshot of the player who joined. Use my code more as inspiration rather than source.

2 Likes

One more question why does your title and everything not have like [] and quotes

Well, for simple variable names like title and url and color (and all that are used here), you don’t actually need to surround it with brackets and quotation marks. Think of it the same as accessing a part in the workspace. You could write workspace.Part1 to access it, and it would work just fine, or you could write workspace["Part1"] and that would work just fine too. If your key value has a space or a number, then you need the brackets to indicate what it is. In our workspace example, if the part had a space between its name and the number, then we could only access it by saying workspace["Part 1"]. In the end, it doesn’t matter much other than readability. Up to you how you want to structure it.

2 Likes