Discord Webhooks and it's utilities!

Learn how to use Http Service and Webhooks to send data to your discord server.

by capsori

Author Avatar

Introduction


Discord Webhooks can be very helpful when working on a game. It allow you to track and/or notify me of whats happening in your game and it's really easy to set up! Without further ado, here’s the tutorial.

What is a Discord Webhook?


Discord's webhooks allow you to automate your messages and send data updates to your Discord text channels. In this tutorial, you will send a notification to your webhook when a specific event on your game goes down, and Discord will make sure that you get those messages on your channel.

Setting up a Webhook on your Discord Server


Adding a Webhook to your server is incredibly easy.

1. Open the Discord Server on which you want to put the Webhook.

2. Click the dropdown arrow and open Server Settings.

3. From there, you want to head over to "Intergrations"

image|100x100

4. Once there, open the Webhooks tab and click Create Webhook.

image|100x100

5. Configure the Webhook to your liking and then save the link for later.


Interacting with the Webhook

Now that the webhook is set up, we can move on to using it in Roblox. Before we get into the code, make sure that HTTPService is enabled. If you don’t know how, simply head over to your roblox game settings and enable HTTP request from there.

Now that HTTPService is enabled, we can get into the actual code of this tutorial. To use the webhook, we will have to use the PostAsync function of HTTPService. For instance:

local http = game:GetService("HttpService")
local link = "" -- Put the link you got from the webhook you created

local Data = {
	["content"] = "This is really cool! I can send messages to discord from Roblox!"
}

Data = http:JSONEncode(Data)
http:PostAsync(link, Data)

Now, go ahead and run this code from a serverscript and see what happens!


What else can we do with this?

There's actually alot of cool stuff you can do with webhooks here's an example:

Player Join Tracker

local http = game:GetService("HttpService")

game:GetService("Players").PlayerAdded:Connect(function(player)
	if not game:GetService("RunService"):IsStudio() then
		local date = os.date("!*t")
		local Data = {
			["content"] = player.Name.." joined your game on "..date.month.."/"..date.day.."/"..date.year
		}
		Data = http:JSONEncode(Data)
		http:PostAsync("[Discord hook here]", Data)
	end
end)

Value Tracker

local http = game:GetService("HttpService")

game:GetService("Players").PlayerRemoving:Connect(function(player)
        local CoinValue = player.Leaderstats.Money.Value
		local Data = {
			["content"] = 
player.Name.." left the game with ".. CoinValue.. " coins!"
		}
		Data = http:JSONEncode(Data)
		http:PostAsync("[Discord hook here]", Data)
	end
end)

View in-game to comment, award, and more!