Changing an image of a webhook

Hi, I’m trying to get an image from a badge and turn the webhook to the image of the badge. I’m using discord for this and I’m not having a lot of luck. Here’s the current script:

local url = "test" --- I didn't want to leak the webhook
local h = game:GetService("HttpService")

while true do
	local badge = math.random(2124451678, 2124451678) ---Insert Random Numbers Here
	local data = {
		
		['embeds'] = {{ 
			
			['title'] = "Badge Bot",
			
			['description'] = "https://roblox.com/badges/"..badge,
			
			['color'] = 6008455,
			
			
			
		}}
		
	}
	
	local finaldata = h:JSONEncode(data)
	h:PostAsync(url, finaldata)
	wait(100) 
end

I’m currently aware that discord in the past blocked requests from Roblox. If you know how please tell me, thanks.

As stated in the Discord api-reference for webhooks, there’s a avatar_url field. Simply assign that field to a string containing a url of the badge’s icon.

ie.

local badge_icon_id = 1;
local data = {
    username = "ReturnedTrue",
    avatar_url = "https://www.roblox.com/asset?id=" .. badge_icon_id,
    embeds = {{
        title = "Special Message",
        description = "Hello, World!",
        color = 6008455
    }}
};

Note that the rbxassetid:// protocol will not work outside of Roblox, hence the website API must be utilised.


FYI: if you find issues with getting the badge’s icon id, see GetBadgeInfoAsync.

1 Like
local url = "webhook"
local h = game:GetService("HttpService")

while true do
    local badge = math.random(2124449010, 2124459010) ---Insert Random Numbers Here

local icon = game:GetService("BadgeService"):GetBadgeInfoAsync(badge).IconImageId
    local data = {
        

        ['embeds'] = {{ 
            
            ['title'] = "Badge Bot",
            
            ['description'] = 'https://roblox.com/badges/'..badge..'',
            
  ['avatar_url'] = "https://www.roblox.com/asset?id="..icon,
        }}
        
    }
    
    local finaldata = h:JSONEncode(data)
    h:PostAsync(url, finaldata)
    wait(30) 
end

Did I do anything wrong here? It still won’t change the avatar profile image

avatar_url should be a field of the main part of the data, not the embed:

local data = {
    ['avatar_url'] = "https://www.roblox.com/asset?id="..icon,
    ['embeds'] = {{
        ['title'] = "Badge Bot",
        ['description'] = 'https://roblox.com/badges/'..badge..'',
    }}
};
1 Like

I tried that, but it’s still the same result

  local data = {
        
['avatar_url'] = "https://www.roblox.com/asset?id="..icon,
        ['embeds'] = {{ 
            
            ['title'] = "Badge Bot",
            
            ['description'] = 'https://roblox.com/badges/'..badge..'',
            
  
        }}
        
    }

Full script:

local url = "webhook"
local h = game:GetService("HttpService")

while true do
    local badge = math.random(2124449010, 2124459010) ---Insert Random Numbers Here

local icon = game:GetService("BadgeService"):GetBadgeInfoAsync(badge).IconImageId
    local data = {
        
['avatar_url'] = "https://www.roblox.com/asset?id="..icon,
        ['embeds'] = {{ 
            
            ['title'] = "Badge Bot",
            
            ['description'] = 'https://roblox.com/badges/'..badge..'',
            
  
        }}
        
    }
    
    local finaldata = h:JSONEncode(data)
    h:PostAsync(url, finaldata)
    wait(30) 
end

Strangely, even going to the web API itself gives a 404 - guess we’re not using it correctly.

Anywho, after some digging I found a thumbnail web API to get exactly what you need. I’ve tried it out and got a permament image link:

"https://t7.rbxcdn.com/82956701f52e9dd0548f6d66f0900313"

Now you can use this for avatar_url without any whoha.

1 Like

How would I apply it to the script? Sorry not used to using api

Unlike the other one I don’t see anywhere to put the badge id

I don’t think this endpoint works anymore. Try https://assetdelivery.roblox.com/v1/asset?id=whatever instead.

2 Likes

This url is already for that badge, I’ve used the API on the docs to retrieve it. All you need to do is assign it to the avatar_url.

PS: Updated because I seemed to use the wrong id (whoops).

Is there a way that I don’t have to manually put the badgeid in the api, and somehow use it in the script?

Yes, most definitely! However, you must use a proxy (ie. rprxy.xyz) since you’ll be sending a request to a Roblox domain.

All you need to do is send a GET request to the thumbnail web API and it’ll return a response with a JSON body (as a string) which can be decoded into a Lua table via JSONDecode. The table will include a data array which includes all the badge thumbnails requested.

For example:

local http_service = game:GetService("HttpService");
local badge_id = 2124449010;

local response = http_service:RequestAsync({
    Url = "https://thumbnails.rprxy.xyz/v1/badges/icons?badgeIds=" .. badge_id .. "&size=150x150&format=Png&isCircular=true",
    Method = "GET",
    Headers = {
        Accept = "application/json" --// You want JSON data
    }
});

if (response.Success) then --// Occasionally can fail
    local body = http_service:JSONDecode(response.Body);
    local thumbnail = body.data[1].imageUrl;
    --// Code
else
    --// Handle for issues
end
3 Likes