Hello, Welcome to this tutorial! The tutorial is entirely devoted to Discord Webhooks and some examples of how to use them in your roblox game and take it to the next level. This is my first tutorial on roblox so I am open to any kind of suggestions about the tutorial. Anways Keep Scrolling down to keep learning…
NOTE: As Of October 2021, Discord has banned any webhook requests coming from the Roblox UserAgent, because it was getting highly abused and used for situations like error logging etc, which it isn’t meant for.
If that is your use case, use Game Analytics, or Sentry.
About The Tutorial
Part 1 - About Webhooks
Part 2 - How to Create A Webhook
Part 3 - Integrating Them Into Our Games
Part 4 - Some Cool Examples of Webhooks used in Roblox games
Part 1 - About Webhooks
Webhooks typically are used to connect 2 Different Applications to transfer data updates from one Application to another. In the case of Discord and Roblox, we can use Discord’s Built-In Webhook Functions to create an easy way to Post Automated Messages into any channel in your server From Roblox using POST Requests.
Part 2 - Creating Your Own Webhook!
Obviously to use webhooks, you should have a server. Then open the server and follow the steps below:
Step 1 - Open the Settings Tab Of Your Server
Step 2 - Navigate to the Webhooks Tab
Step 3 - Click on the Create Webhook Button
Step 4 - Configure you Webhook!
Now that you have come till here, you have some options that you can configure:
-
Choose the Channel - You can select the desired channel you want the posts to be sent in.
-
Name it - You can give an Unique name to the webhook to distinguish between Multiple Webhooks (If you have.)
-
Upload An Icon - Some Icon…
After doing all that, copy your Webhook URL and save it somewhere. As we will need it later on.
And…There you go! You just created your own Discord Webhook! Now lets move on to integrating them into our games in the next section
Part 3 - Integrating the Webhook With Roblox Game
You just created your webhook in the last section, now lets move on to integrating the Webhook with your game to send simple messages from Roblox to a Discord Channel!
But first of all, please make sure that your HTTPService Is Enabled, If its not you can enable it by going to Game Settings > Options and Turn on HTTPService
After Ensuring that it is enabled, lets move on to the Actual part!
First of all you have to get the HttpService in your script, which can done with something like this:
local HS = game:GetService("HttpService")
After This you can store your WebhookURL into a variable, just to make the code a bit clean.
local WebhookURL = "https://discordapp.com/api/webhooks/xxxxxxxx/xxxxxx"
--Replace your link with the link in the Quotes.
Then you can store the message you want to send in a table, like the following.
local MessageData = {
["content"] = "Hoi, Test message arrived!"
}
MessageData = HS:JSONEncode(MessageData)
--We used JSONEncode to convert the Lua Table into a Json String
And Finally you can use the POST
method to Send a HTTP Post Request to the URL with the Message.
HS:PostAsync(WebhookURL,MessageData)
Your Final Script should look something like this:
local HS = game:GetService("HttpService")
local WebhookURL = "https://discordapp.com/api/webhooks/xxxxxx/xxxxxxx"
--Replace your link with the link in the Quotes.
local MessageData = {
["content"] = "Hoi, Test Message arrived!"
}
MessageData = HS:JSONEncode(MessageData)
--We used JSONEncode to convert the Lua Table into a Json String
HS:PostAsync(WebhookURL,MessageData)
The Above was a very simple example to demonstrate how you can use the Discord Built-In Webhooks Function to send a message from Roblox to Discord!
Part 4 - A Cool Example!
As I said in the beginning of the tutorial, you can use webhooks to basically take your game to the next level and in some ways save you some time also!
A Feedback UI, which will allow players to send feedback which land directly on your discord Server!
For the UI you can design it as you like, but I will guide you through the script for controlling the max length you can write, the Function of the Send Button etc.
ControllerForUI Script
local maxCharacters = 500 -- Maximum Characters
local player = game.Players.LocalPlayer
local open = false
local feedbackMain = script.Parent.FeedbackMain
feedbackMain.CharactersLeft.Text = maxCharacters - #feedbackMain.InputBox.Input.Text
feedbackMain.InputBox.Input.Changed:Connect(function()
feedbackMain.CharactersLeft.Text = maxCharacters - #feedbackMain.InputBox.Input.Text
if maxCharacters - #feedbackMain.InputBox.Input.Text < 0 then
feedbackMain.CharactersLeft.TextColor3 = Color3.fromRGB(255,50,50)
feedbackMain.SendButton.Style = Enum.ButtonStyle.RobloxRoundButton
else
feedbackMain.CharactersLeft.TextColor3 = Color3.fromRGB(255,255,255)
feedbackMain.SendButton.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
end
end)
local db = false
feedbackMain.SendButton.MouseButton1Click:Connect(function()
if not db and maxCharacters - #feedbackMain.InputBox.Input.Text >= 0 then
db = true
local msg = feedbackMain.InputBox.Input.Text
feedbackMain.InputBox.Input.Text = "Sending Message..."
local response = game.ReplicatedStorage.FilteringFunction:InvokeServer(msg)
feedbackMain.InputBox.Input.Text = response
wait(5)
if feedbackMain.InputBox.Input.Text == response then
feedbackMain.InputBox.Input.Text = "Type feedback/bug report here"
end
db = false
end
end)
script.Parent.Button.MouseButton1Click:Connect(function()
open = not open
if open then
feedbackMain:TweenPosition(UDim2.new(1,-300,1,-300),"Out","Quint",0.3,true)
else
feedbackMain:TweenPosition(UDim2.new(1,100,1,-300),"Out","Quint",0.3,true)
end
end)
You can make the UI according to yourself and change the Tweens Values or the Max Characters.
After doing all that, you can create a Remote Function in Replicated Storage with the corresponding name, in our case we used FilteringFunction
as that is what we used in the first script.
Now lets move on to the Server Side, which will Post the Request so the message is sent to the Discord Server! For this you can write up a script something like the following.
local webhookURL = "https://discordapp.com/api/webhooks/xxxx/xxxxxxx"
local filteringFunction = game.ReplicatedStorage.FilteringFunction
local ChatService = game:GetService("Chat")
local HTTP = game:GetService("HttpService")
function filteringFunction.OnServerInvoke(player, msg)
local FilteredMessage = ChatService:FilterStringForBroadcast(msg, player)
--Filter the message, before sending it to the webhook.
local payload = HTTP:JSONEncode({
content = FilteredMessage,
username = "Submitted By "..player.Name
})
HTTP:PostAsync(webhook, payload)
return "Feedback recieved!"
end
Note: You have to Filter the message before sending it to the webhook, for security reasons.
And that would do the job! A quick preview of what this will result in:
https://gyazo.com/d7787ebc001d6e722daf5a9a0d1df348
As you can see, alot can be done with Webhooks! Thats all For Now guys, please suggest me how I can improve my tutorial! Thanks for reading!
If you want to contact me, you can on DevForum itself or on my Discord - Neil#1234
Some Important Points to Note
- The Discord’s API rate limits requests in order to prevent abuse and overload - rate-limits
- Webhooks shouldn’t be used for error logging.
- Be sure to implement a rate limiting for your Roblox to Discord Integration, otherwise players might use it in a bad way and hit the Discord rate limits.
Again Thanks For reading