How to make a discord webhook that logs gamepass and dev products purchases?
How to make a discord webhook that logs gamepass and dev products purchases?
1 answer
Well first you need to create webhook in Discord, select any channel and go to its settings > Connections > Webhooks > New Webhook (I have it in other language so the settings have bit other name) and now you need to copy the webhook URL. Now put it into your script and use HttpService. So
local HttpService = game:GetService("HttpService")
It has function called PostAsync which.. posts given JSON string (Arg 2) into given url (Arg 1, Webhook in this case). So to create JSON file you need to use JSONEncode function which will convert given table into JSON string. So do:
local HttpService = game:GetService("HttpService")
local Content = HttpService:JSONEncode(
{
content = "hello",
username = "WideSteal",
}
)
Now here, content is message that will be sent to the discord and username is the name of the bot that will be displayed. There are also other properties like avatar_url which is the profile picture, you can see them all here. NOTE: All properties MUST be named like said in the API, otherwise it won't work! So now you need to send the content by using the PostAsync!
In this case, first argument as i said is the url (Webhook) and the second would be the content.
local Webhook = "Your webhook that you copied"
HttpService:PostAsync(Webhook, Content)
Now it should post it into channel the webhook was created in. But there is a chance that it will fail, it is not 100% success so use Pcalls! Pcall's first argument is function that will be protected so what is enough is:
pcall(HttpService.PostAsync, HttpService, Webhook, Content)
And now you have protected it from erroring. The reason why 2 argument here is HttpService is because PostAsync is called with : (Semicolon) because it requires self keyword. The other 2 arguments are arguments that the function PostAsync requires, it's that simple. Pcalls return 2 arguments, boolean (If succeeded) and string? (Error if it did not success, only returns if did not success). So the whole script would be looking like this:
local HttpService = game:GetService("HttpService")
local Webhook = "Your webhook"
local Content = HttpService:JSONEncode(
{
content = "hello",
username = "WideSteal",
}
)
pcall(HttpService.PostAsync, HttpService, Webhook, Content)
And this is it. This is how to make webhook. You would have to use PromptPurchaseFinished for checking when someone buys your product but this is not request site so cya
2 comments
Why do I think that he know what you just stated above, and just came to get the script for triggering that webhook on purchase?
i thought that too hehe but i just wanted to train how to make good looking answer and i knew it's going to get moderated so why not, does my answer look good? or is it too ugly
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
boooooooooo have you tried at least something yourself, this is not request site