Avatar URL for discord embed

I am trying to add an Avatar Headshot to a discord embed.
The Webhook works fine it’s just the Avatar Headshot.

https://www.roblox.com/headshot-thumbnail/image?userId='.. userId ..'&width=420&height=420&format=png

Is this deprecated or am I just typing something wrong?

8 Likes

Not sure why it is not working but use this instead:

https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=USER_ID_HERE&size=420x420&format=Png&isCircular=false

BE ADVISED that this returns an OBJECT.

Please view the exemplar below:

{"data":[{"targetId":56462889,"state":"Completed","imageUrl":"https://tr.rbxcdn.com/5d5c7dbf886c1f5299bd15501959a3e8/420/420/AvatarHeadshot/Png"}]}

You must send a get request using HttpService and then :FromJSON. Then index into imageUrl to get the Url. This gives you a nice crispy good looking image.

1 Like

I got an error that says…

HttpService is not allowed to access ROBLOX resources

How do I get around that?

1 Like

You’ll need to use a proxy, as Roblox deliberately rejects HttpService from accessing resources.

1 Like

You can use GetUserThumbnailAsync() instead

Players:GetUserThumbnailAsync(userid, thumbnailtype, thumbnailsize)
1 Like

How do I go about using a proxy?
I’ve never done it before.

1 Like

Unfortunately this only produces a ROBLOX oriented render. What we are attempting to do here is linkify it for external access, for example in this case, it’s for Discord.

1 Like

As in from, a discord bot? Or passing info from a roblox server to discord?

1 Like

A Discord webhook, which is delivered data from the Roblox server.

1 Like

There are several proxy services like Hyra, but if you’re concerned about privacy, then there are tutorials and open-sourced projects around the internet on creating your own proxy services, so you might want to check those out.

1 Like

If it’s from a Roblox server then,
GetUserThumbnailAsync() can be used, since it will only return a tuple containing the image url and a boolean to check if its loaded or not.

1 Like

Hyra is for “Roblox to Discord”.

I need to get the imageUrl from Roblox, without it throwing me a “HttpService is not allowed to access ROBLOX resources”

1 Like

I don’t think this will work. I’m going to try it again though.

ROBLOX uses their own little embedding software that takes shortened links like this:

rbxthumb://type=AvatarHeadShot&id=56462889&w=180&h=180
(This is the result of GetUserThumbnailAsync(). This is an encoded ROBLOX link)

and transfers them to this:

https://tr.rbxcdn.com/5d5c7dbf886c1f5299bd15501959a3e8/180/180/AvatarHeadshot/Png

There is no current method of going from one to the other. The only way to do this is by sending a GET request to the ROBLOX server itself sadly.

1 Like

Yes, this does not work.
HTTP 400 (Bad Request)

4 Likes

You need to use roblox api and proxy.
Example:

local http = game:GetService("HttpService")
local function getheadshot(userid)
	local s, data = pcall(function()
		return http:JSONDecode(http:GetAsync(`https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds={userid}&size=420x420&format=Png&isCircular=false`))
	end)
	if s and data then
		return data.data[1].imageUrl
	else
		return "https://t3.rbxcdn.com/9fc30fe577bf95e045c9a3d4abaca05d" --example, if it was not possible to get an avatar
	end
end
print(getheadshot(1)) --> https://tr.rbxcdn.com/ea3425c2b657de9af16c629441e0dcb2/420/420/AvatarHeadshot/Png
2 Likes