Discord http 400 (bad request) error

I’m trying to get my web hook to send but it keeps giving me an “HTTP 400 (Bad Request)” error

it’s supposed to be sending a web hook to my own web hook i had put in my variables

I tried looking on the devforum, reverting my old code that used to work same issue I come across

--[[
	- Thigbr
	- 03/28/21
]]

-- // Services
local http = game:GetService("HttpService")

-- // Configuration
local DiscordWebhook = "https://discord.com/api/webhooks/825962296354275328/zpUZ_Ve5aLDXoJ0WkEQ1fX5T9EInJyBCgAWPWwfl2g4YtgPfDLsCELp_JYYSW_"

-- //
local module = {}
module.__index = module

function getRealTime(Time)
	local ExactTime     = os.date("!*t",Time)
	local Hr, min, sec, day, mnth, year = ExactTime.hour,  ExactTime.min, ExactTime.sec, ExactTime.day, ExactTime.month, ExactTime.year
	return ("%0.0f-%0.0f-%0.0fT%0.0f:%0.0f:%0.0fZ"):format(year, mnth, day, Hr, min, sec)
end 

function module.GetTable(plr, refunder, amount)
	local self = setmetatable({
		Player = plr.Name,
		PlayerUserId = plr.UserId,
		Refunder = refunder.Name,
		RefunderUserId = refunder.UserId,
		Amount = amount
	}, module)
	
	return self
end

function module:SendInfo()	
	local data = {
		embeds = {
			{
				author = {name = "Player Refunded!"},
				title = "Server: "..game.JobId,
				description = self.Player..":"..self.PlayerUserId.." Has refunded ".."**"..self.Amount.."$**".." to Player "..self.Refunder..":"..self.RefunderUserId,
				timestamp = getRealTime(tick()),
				color = "2053964",		
				type = "rich",
			}
		}
	}	
	local newdata = http:JSONEncode(data)
    http:PostAsync(DiscordWebhook,newdata)
end

function module:SendError()	
	local data = {
		embeds = {
			{
				author = {name = "An error occured!"},
				title = "Server: "..game.JobId,
				description = "Xd",
				timestamp = getRealTime(tick()),
				color = "15417151",		
				type = "rich"
			}
		}
	}	
	local newdata = http:JSONEncode(data)
    http:PostAsync(DiscordWebhook,newdata)
end

return module

Ensure you have HTTP requests enabled on your game.

I do, my web hook looks something like this if it has to do with anything being blocked “https://discord.com/api/webhooks/825962296354275328/zpUZ_Ve5aLDXoJ0WkEQ1fX5T9EInJyBCgAWPWwfl2g4YtgPfDLsCELp_JYYSW_

The colour of an embed is meant to be in HEX, is it not? What do those numbers represent currently?

Th color of the embed isn’t the problem, I’ve tried like 3-4 public web hook scripts and it gives me the same error.

Your ISO formatting function is bit wrong, try this one:

function getRealTime(Time)
	local ExactTime     = os.date("!*t",Time)
	local Hr, min, sec, day, mnth, year = ExactTime.hour,  ExactTime.min, ExactTime.sec, ExactTime.day, ExactTime.month, ExactTime.year
	return ("%d-%02d-%02dT%02d:%02d:%02dZ"):format(year, mnth, day, Hr, min, sec)
end

%d stands for digits, %02d forces minimum 2 digits.

3 Likes

Thank you, I must of miss clicked and added it in there without knowing