Hey guys, so I am making a mod call system that works through discord webhooks, even tho i made the webhook and stuff, i still can’t manage for it to work.
local HttpService = game:GetService("HttpService")
local WebhookURL = "https://discord.com/api/webhooks/1184447576796299274/hPHIuqhOgNHHotDHYmVcnBxGRmjN8BQArb8qUf779PvTKp6eFIz0-R-S-hB7U8zy-ZA9"
local function postToDiscord(Message)
local Data = {
["content"] = Message
}
Data = HttpService:JSONEncode(Data)
HttpService:PostAsync(WebhookURL, Data)
end
game.ReplicatedStorage.Report.OnServerEvent:Connect(function(player,reason)
postToDiscord("**"..player.Name.."** has requested for a moderator to come for the reason of: **"..reason.."** ||@here||")
end)
Else make a pcall() the function might not work properlly
local success = nil
local errorMsg = nil
local attempt = 1
repeat
success, errorMsg = pcall(function()
HttpService:PostAsync(WebhookURL, Data, Enum.HttpContentType.ApplicationUrlEncoded, false)
end)
attempt += 1
if not success then
task.wait(1)
warn(errorMsg)
end
until success or attempt == 5
local HttpService = game:GetService("HttpService")
local WebhookURL = "https://discord.com/api/webhooks/1184447576796299274/hPHIuqhOgNHHotDHYmVcnBxGRmjN8BQArb8qUf779PvTKp6eFIz0-R-S-hB7U8zy-ZA9"
local function postToDiscord(Message)
local Data = {
["content"] = Message
}
local Headers = {
["Content-Type"] = "application/json"
}
local RequestData = {
Url = WebhookURL,
Method = "POST",
Headers = Headers,
Body = HttpService:JSONEncode(Data)
}
HttpService:PostAsync(RequestData)
end
game.ReplicatedStorage.Report.OnServerEvent:Connect(function(player, reason)
postToDiscord("**" .. player.Name .. "** has requested for a moderator to come for the reason of: **" .. reason .. "** ||@here||")
end)
Also don’t forget to change your webhook now that it’s public.
the potential issue with the use of the HttpService:PostAsync method. The PostAsync method typically requires additional parameters, such as the content type and headers. You should ensure that your request is properly formatted by providing the necessary headers and specifying the content type as JSON.
One, get another discord webhook, someone can do something dangerous with that information, and Two use a 3rd party webhook rerouter/proxy, discord blocked roblox servers from sending anything through their HTTP(S) servers.
Try out or test random servers until you do get it, but also when you do, delete the current one just in case it gets compromised.