How do i put a players avatar headshot png in a discord webhook embeds thumbnail?

So, im working on a thing with webhooks sending a embed to discord, but i cant seem to get the thumbnail working, getting the player avatars headshot picture on the embed
heres the code-

local HttpService = game:GetService('HttpService')
local url = "https://discord.com/api/webhooks/..."
local PictureUrl = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
	local data = 
		{
			["embeds"] = {{
				["title"] = player.Name,
				["color"] = tonumber(0xffffff),
				["thumbnail"] = PictureUrl,
				["fields"] = {
					{
						["name"] = "Mesage",
						["value"] = text,
					},
				}
			}}
		}
	local newdata = HttpService:JSONEncode(data)
	HttpService:PostAsync(url, newdata)

it throws an error - HTTP 400 (Bad Request)
any help would be appreciated

3 Likes

This answer may help you. I think you are missing the correct formatting for sending a discord webhook.
There’s also this module if you want to use it!

You need to use the roblox API to get the link to the image itself, I used a proxy (roproxy) since roblox forbids using its api in the game.
Example:

local HttpService = game:GetService('HttpService')
local url = "https://discord.com/api/webhooks/..."

local s, PictureUrl = pcall(function()
	return HttpService:JSONDecode(HttpService:GetAsync("https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds="..player.UserId.."&size=150x150&format=Png")) --use api and proxy to get LINK, you can change size
end)
if s and PictureUrl then
	PictureUrl=PictureUrl.data[1].imageUrl
else
	PictureUrl="https://t3.rbxcdn.com/9fc30fe577bf95e045c9a3d4abaca05d" --link if can't get player headshot (default img)
end

local data = 
	{
		["embeds"] = {
			["title"] = player.Name,
			["color"] = tonumber(0xffffff),
			["thumbnail"] = {
				["url"] = PictureUrl
			},
			["fields"] = {
				{
					["name"] = "Message",
					["value"] = text,
				},
			}
		}
	}
local newdata = HttpService:JSONEncode(data)
HttpService:PostAsync(url, newdata)

PictureUrl will be like this: https://tr.rbxcdn.com/8bac92eaf8e62c56287efe63d0bd5a77/150/150/AvatarHeadshot/Png
Api docs: Swagger UI

11 Likes

thank you so much im been wanting this to work for months. idk why i just love the little avatars next to players feedback messages. thank you :heart_on_fire:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.