I’m trying to make it so that when a function is called, a webhook is sent.
Whenever I fire the function(or the webhook in any way), it gives me a error 400: bad request. At first I thought this was because I was testing it in studio, but when I tried it in Roblox Player it also failed to work.
I’ve tried firing the webhook off of a remote event, and just off of the player joining and it still failed to work.
Before anyone asks, YES, HTTPRequests are enabled.
Code
--This is a server sided script
function bruhWhyRobloxSuckWithHTTP(playerPassed)
local success, errorMsg = pcall(function()
local http = game:GetService("HttpService")
local messageToSend = "!promote"..playerPassed
Data = http:JSONEncode(messageToSend)
http:PostAsync("MyDiscordWebHook", Data) --Put the link you saved between the two quotes.
print("User passed a user!")
end)
print(success, errorMsg)
end
You are just sending just a content string to Discord, which isn’t how their webhooks work. See their webhook documentation.
You need to send a proper webhook structure. Something like this would work (although if you look at the link above, you can see all of the valid arguments).
Alright, thank you! This is my first time using webhooks, so I simply thought I could fire a string straight to discord. I’ll be sure to read their documentation sometime soon.
Most websites have documentation behind their endpoints. Discord’s is… a little bit more complicated, so I can understand that. Just make sure you check with each website you send requests to!