Hello! I’m trying to get the player’s avatar for a webhook but it doesn’t seem to work. I believe the problem is at the URL. Is there a way to fix this?
I’ve looked at other documents as well and tried all of their solutions but it doesn’t seem to work.
Helps are appreciated!
local function mainhandler(p, msg)
if iscommand(p, msg) then
local fields = {
{
['name'] = "User",
['value'] = p.Name,
['inline'] = true
},
{
['name'] = "UserID",
['value'] = p.UserId,
['inline'] = true
},
{
['name'] = "Command",
['value'] = msg,
['inline'] = true
},
{
['name'] = "Rank",
['value'] = p:GetRoleInGroup(13804229),
['inline'] = true
}
}
discord:createEmbed(url, "HD Admin Command", "A command was used in Serenity:", fields, "https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds="..p.UserId.."&size=180x180&format=Png&isCircular=false")
end
end
Here’s the updated line to see if I did anything wrong:
discord:createEmbed(url, "HD Admin Command", "A command was used in Serenity:", fields, "https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds="..tostring(p.UserId).."&size=720x720&format=Png&isCircular=false")
That is a dictionary containing an array, which contains a dictionary. Inside that last dictionary there is a key, “imageUrl”. That is what you want to pass through to the module.
You could modify the module script to get the imageUrl, or get it before calling the :createEmbed function.
To get it you just need to do a simple Http request:
local HttpService = game:GetService("HttpService")
function getAvatarThumbnail(UserId:number) : (boolean,string)
local Url = "https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds="..UserId.."&size=180x180&format=Png&isCircular=false"
local Response = HttpService:RequestAsync({
Url = Url,
Method = "GET",
Headers = {},
Body = nil
})
if Response.Success then
local Data = HttpService:JSONDecode(Response.Body)
return true, Data["data"][1]["imageUrl"]
else
return false, Response.Body
end
end
local Success, Data = getAvatarThumbnail(2906349392)
local Success, ImageUrl = getAvatarThumbnail(p.UserId)
discord:createEmbed(
url,
"HD Admin Command",
"A command was used in Serenity:",
fields,
imageUrl
)
Make sure to handle errors, i.e. If Success is false you might want to pass a placeholder image instead of imageUrl as it will be nil