Adding queues to a webhook join/leave log?

Hi!
Right now, I have this for my embeds.

local Players = game:GetService("Players")
local http = game:GetService("HttpService")
local webhook = "https://webhook.lewistehminerz.dev/api/webhooks/908503758705676288/J3ktPStALQfNvgCUN7FXnDarxDb9VuHesbJ6KjLG4El7vplZof9eVMx_hG2p5Z0pN2bH" --Enter your Webhook link here
local queue = 0

Players.PlayerAdded:Connect(function(plr)
	local data = 
	{
		["contents"] = "",
		["username"] = plr.Name .. " - (#"..plr.userId..")",
		["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
		["embeds"] = {{
			["title"]= plr.name,
			["description"] = plr.Name .. " joined the Game",
			["type"]= "rich",
			["color"]= tonumber(0x6AA84F),
			["fields"]={
				{
					["name"]="Event: Player joined",
					["value"]="User: **"..plr.Name.."** with ID: **"..plr.UserId.."** has joined [game](https://www.roblox.com/games/".. game.PlaceId..")/[Profile](https://www.roblox.com/users/"..plr.UserId.."/profile)",
					["inline"]=true}}}}
	}
	http:PostAsync(webhook,http:JSONEncode(data))
end)

Players.PlayerRemoving:Connect(function(plr)
	local leavedata = 
	{
		["contents"] = "",
		["username"] = plr.Name .. " - (#"..plr.userId..")",
		["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
		["embeds"] = {{
			["title"]= plr.name,
			["description"] = plr.Name .. " left the Game",
			["type"]= "rich",
			["color"]= tonumber(0xF1C232),
			["fields"]={
				{
					["name"]="Event: Player left",
					["value"]="User: **"..plr.Name.."** with ID: **"..plr.UserId.."** left [game](https://www.roblox.com/games/".. game.PlaceId..")/[Profile](https://www.roblox.com/users/"..plr.UserId.."/profile)",
					["inline"]=true}}}}
	}
	http:PostAsync(webhook,http:JSONEncode(leavedata))
end)

But then I remembered API requests would stop after a bit, and the webhook would be backed up for a bit, say if I restarted my game. All players would be shoved into a queue, and instantly put back once the server accepts it. So, how would I add queues to my webhook to make sure it doesn’t instantly overload?
I do want it in the end to post it.
Thanks!
Also, right now I think my Creating Plot embed code is safe to overload.

1 Like


Shoutout to Cyrus :+1:
If I took away the ink I would get banned.
The webhook is no good anymore, thanks for the heart attack :sunglasses:
Anyways, it’s still an issue.

HTTP Queuing

Sounds like rate limiting. If so, you may be useful checking this application out. (credit to @davness)

How to use this in your system

HttpQueue.rbxm (28.4 KB)

  • Drop the “HttpQueue” script into ServerScriptService and move over to your webhook script.
  • Replace your script with the following, making changes to the webhook link where appropriate:
local JoinMessage_Queue = Http.HttpQueue.new({
    retryAfter = {cooldown = 10}, -- How long you should wait until trying again if it rate limits you
    maxSimultaneousSendOperations = 5 -- A suitable amount for discord, tells the script how many items from the queue it can send in one go
})

players.PlayerAdded:Connect(function(plr)
	local data = 
	{
		["contents"] = "",
		["username"] = plr.Name .. " - (#"..plr.userId..")",
		["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
		["embeds"] = {{
			["title"]= plr.name,
			["description"] = plr.Name .. " joined the Game",
			["type"]= "rich",
			["color"]= tonumber(0x6AA84F),
			["fields"]={
				{
					["name"]="Event: Player joined",
					["value"]="User: **"..plr.Name.."** with ID: **"..plr.UserId.."** has joined [game](https://www.roblox.com/games/".. game.PlaceId..")/[Profile](https://www.roblox.com/users/"..plr.UserId.."/profile)",
					["inline"]=true}}}}
	}
    local request = Http.HttpRequest.new(webhook_link,"POST", nil, data) -- Create the information for our request so that we can queue it
    JoinMessage_Queue:Push(request):andThen(function(response) -- Here is where the info for the person who joined is lined up waiting to be sent to your Discord webhook.
        print(response.StatusMessage) -- This tells you if it worked or not.
    end)
end)

players.PlayerRemoving:Connect(function(plr)
	local data = {
		["contents"] = "",
		["username"] = plr.Name .. " - (#"..plr.userId..")",
		["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
		["embeds"] = {{
			["title"]= plr.name,
			["description"] = plr.Name .. " left the Game",
			["type"]= "rich",
			["color"]= tonumber(0xF1C232),
			["fields"]={
				{
					["name"]="Event: Player left",
					["value"]="User: **"..plr.Name.."** with ID: **"..plr.UserId.."** left [game](https://www.roblox.com/games/".. game.PlaceId..")/[Profile](https://www.roblox.com/users/"..plr.UserId.."/profile)",
					["inline"]=true}}}}}
    local request = Http.HttpRequest.new(webhook_link,"POST", nil, data) -- Create the information for our request so that we can queue it
    JoinMessage_Queue:Push(request):andThen(function(response) -- Here is where the info for the person who joined is lined up waiting to be sent to your Discord webhook.
        print(response.StatusMessage) -- This tells you if it worked or not.
    end)
end)

What if some big hotshot VIP joins my experience and I want to know first?
You can push specific requests the queue. With this, you can check if their name is a big important person and make their request a priority, meaning that they will be the next to have their message sent even if they joined after others.

JoinMessage_Queue:Push(request, Http.HttpRequestPriority.Prioritary)

This should do the trick, tinker around where needed and play around with the timings at the top of the script if this doesn’t solve your issue immediately.

Example code by @davness, altered for the less experienced and to work with Discord. In no way do I take any credit.

1 Like


Also, will the queue work Game-wide? I dont want it trying tto push 5 people per server.

My bad, after {cooldown = 10} add a comma.

As for your other query and from what I’m aware with HTTPQ, sadly not, however you can always set the SImultaneousSendOperations to 1, meaning that everytime it is able to, it will send the first request. With this across multiple servers, it would work as several queues combined into one.

If the original answer helped, make sure to give it a solution :white_check_mark:

1 Like