HttpService:PostAsync() Issue

Hi everyone, I’m a novice developer trying to make a modcall system. It throws a bad request when I try to do so. Here is the Server Script:

--// Services
local Discord = require(script.WebhookService)
local msgservice = game:GetService("MessagingService")


--// Settings (For easier modification if i wanted to edit something)
local mods = {2376973163} --// UserId of mods in here

game.Players.PlayerAdded:Connect(function(plr)
	task.wait(1)
	if table.find(mods, plr.UserId) then
		local gui = script.modCallrequests:Clone()
		gui.Parent = plr:WaitForChild("PlayerGui")
	end
end)

local success, errormsg, connection = pcall(function()
	msgservice:SubscribeAsync("modreq", function(msg)
		local messages = msg.Data
		print(messages)
		game.ReplicatedStorage.updatereq:FireAllClients(messages[1], messages[2], messages[3], messages[4])
		print("Subscribed and fired")
	end)
	
end)


game.ReplicatedStorage.callMod.OnServerEvent:Connect(function(player, reason, offender)
	if not script:FindFirstChild(player.Name) then
		local cooldownName = Instance.new("BoolValue")
		cooldownName.Name = player.Name
		cooldownName.Parent = script
		game:GetService("Debris"):AddItem(cooldownName, 60)
		msgservice:PublishAsync("modreq", {reason, player.Name, game.JobId, offender})
		local fields = {
			{
				['name'] = "UserId",
				['value'] = player.UserId,
				['inline'] = true
			},
			{
				['name'] = "Reason",
				['value'] = reason,
				['inline'] = true
			}
		}
		Discord:createEmbed("https://discord.com/api/webhooks/[PRIVATE]", "New Report", player.Name .. " reported " .. offender, fields)
		
	end
end)

Module Script:

local webhookService = {}

local https = game:GetService("HttpService")


function webhookService:createMessage(url, message : string)
	local data = {
		["content"] = message
	}
	local finalData = https:JSONEncode(data)
	local finalUrl = string.gsub(url, "discord.com", "webhook.lewisakura.moe")
	local finalBackupUrl = string.gsub(url, "discord.com", "webhook.newstargeted.com")
	local good, bad = pcall(function()
		https:PostAsync(finalUrl, finalData)
	end)
	if good then
		print("Webhook Request Success!")
	else
		print("Webhook Request Failed " .. bad .. " Trying backup URL")
		https:PostAsync(finalBackupUrl, finalData)
	end
end


function webhookService:createEmbed(url, title : string, message :string , fields, image)
	local data = {
		['content'] = "",
		['embeds'] = {{
			["image"] = {["url"] = image},
			['title'] = "**"..title.."**",
			['description'] = message,
			['type'] = "rich",
			["color"] = tonumber(0xffffff),
			['fields'] = fields

		},
		},
	}
	local finalData = https:JSONEncode(data)
	local finalUrl = string.gsub(url, "discord.com", "webhook.lewisakura.moe")
	local finalBackupUrl = string.gsub(url, "discord.com", "webhook.newstargeted.com")
	local good, bad, atmp = nil,nil,0
	repeat
		good, bad = pcall(function()
			https:PostAsync(finalUrl, finalData)
		end)
		if bad then
			print(bad)
			wait(2)
                        atmp += 1
		end
	until good or atmp >= 3
	
	if good then
		print("Webhook Request Success!")
	else
		print("Webhook Request Failed " .. bad .. " Trying backup URL")
		https:PostAsync(finalBackupUrl, finalData)
	end
end


function webhookService:createAuthorEmbed(url, authorName : string, iconurl, description : string, fields)
	local data = {
		["embeds"] = {{
			["author"] = {
				["name"] = authorName,
				["icon_url"] = iconurl,
			},
			["description"] = description,
			["color"] = tonumber(0xFFFAFA),
			["fields"] = fields
			
			
		}},
	}
	
	local finalData = https:JSONEncode(data)
	local finalUrl = string.gsub(url, "discord.com", "webhook.lewisakura.moe")
	local finalBackupUrl = string.gsub(url, "discord.com", "webhook.newstargeted.com")
	
	local good, bad = pcall(function()
		https:PostAsync(finalUrl, finalData)
	end)
	if good then
		print("Webhook Request Success!")
	else
		print("Webhook Request Failed " .. bad .. " Trying backup URL")
		https:PostAsync(finalBackupUrl, finalData)
	end
end


return webhookService

Client Script:

local btn = script.Parent
btn.MouseButton1Click:Connect(function()
	if #btn.Parent.reason.Text >= 4 then
		game.ReplicatedStorage.callMod:FireServer(script.Parent.Parent.reason.Text, script.Parent.Parent.target.Text)
	end
end)

it looks like you don’t aren’t putting in the “image” parmeteter in discord:createEmbed (when you call it in your serverscript)

if you don’t want an image, it doesn’t say you need one on the discord webhook documentation.
so just remove ["image"] in the embeds so you are left with

['embeds'] = {{
			['title'] = "**"..title.."**",
			['description'] = message,
			['type'] = "rich",
			["color"] = tonumber(0xffffff),
			['fields'] = fields

		},

in your module script.

To my knowledge, Discord has blocked Roblox requests because in the past people spammed their API too much.

You can use a proxy in order to bypass this.

1 Like