Getting Started
Sending a basic message
Frist and formost you should require the voyager module script and store the result inside a variable.
| local voyager = require(path_here.voyager)
|
Then after that we can require all the objects we need. In this case, since we only need to send a basic message to Discord we only need the Webhook object.
| local voyager = require(path_here.voyager)
local webhook = voyager.Webhook
|
Now we need to create a new Webhook instance to start sending messages, to do that call the webhook's "new" constructor method.
The constructor method requires 2 arguments to be passed. The first argument must be the webhook's id, and the second argument must be the webhook's token.
| local voyager = require(path_here.voyager)
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
|
How do I obtain my webhook's id and token?
https://discord.com/api/webhooks/ID/TOKEN
Compare your webhook's url to the one above, that should allow you to easily find the id and token of your webhook.
Now that we have a Webhook instance, we can send messages to Discord by using the webhook's SendMessage method.
| local voyager = require(path_here.voyager)
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
webhook:SendMessage("Hello, world!")
|
If you require a more indepth description about the webhook's SendMessage function you can find it here.
And it's as simple as that! if you run the script, a message like the one below should appear in the webhook's channel.
Making something with Voyager
This is only an example
Please don't actually implement this example into your games, join logging takes up queue spots on the proxy just to deliver no real important information. This is just meant to be a fun little example you can learn from.
Now lets make a script that sends a Discord message when a player joins the game.
Using the code from the previous section we already have a good amount of work done.
| local voyager = require(path_here.voyager)
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
webhook:SendMessage("Hello, world!", nil, true, false)
|
We will need to get the players service and use it's PlayerAdded event to know when to send a message.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
Now we'll create a new Embed instance.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
Now we'll set the embed's author using the embed's SetAuthor method.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
Now we'll give the embed some color using the embed's SetColor method
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:SetColor(Color3.fromRGB(85, 255, 127))
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
Now we'll give the embed some fields so we can see some more information about the player using the embed's AddField method.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:SetColor(Color3.fromRGB(85, 255, 127))
:AddField(
"Account Age",
"**" .. player.AccountAge .. "** Days"
)
:AddField(
"Has Verified Badge?",
tostring(player.HasVerifiedBadge)
)
:AddField(
"From Game",
"[Game Link](https://www.roblox.com/games/" .. game.PlaceId .. ")"
)
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
Lastly we're gonna add a timestamp to the embed's footer using the embed's SetTimestamp method.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:SetColor(Color3.fromRGB(85, 255, 127))
:AddField(
"From Game",
"[Game Link](https://www.roblox.com/games/" .. game.PlaceId .. ")"
)
:AddField(
"Account Age",
"**" .. player.AccountAge .. "** Days"
)
:AddField(
"Has Verified Badge?",
tostring(player.HasVerifiedBadge)
)
:SetTimestamp()
webhook:SendMessage("Hello, world!", nil, true, false)
end)
|
And now we can edit the SendMessage method to send the message.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:SetColor(Color3.fromRGB(85, 255, 127))
:AddField(
"From Game",
"[Game Link](https://www.roblox.com/games/" .. game.PlaceId .. ")"
)
:AddField(
"Account Age",
"**" .. player.AccountAge .. "** Days"
)
:AddField(
"Has Verified Badge?",
tostring(player.HasVerifiedBadge)
)
:SetTimestamp()
webhook:SendMessage(nil, { embed })
end)
|
Lastly we'll add some basic error handling.
| local playerService = game:GetService("Players")
local voyager = game:GetService("ServerStorage").voyager
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
playerService.PlayerAdded:Connect(function(player : Player)
local embed = voyager.Embed.new()
:SetAuthor(
player.DisplayName .. " Joined!",
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:SetColor(Color3.fromRGB(85, 255, 127))
:AddField(
"From Game",
"[Game Link](https://www.roblox.com/games/" .. game.PlaceId .. ")"
)
:AddField(
"Account Age",
"**" .. player.AccountAge .. "** Days"
)
:AddField(
"Has Verified Badge?",
tostring(player.HasVerifiedBadge)
)
:SetTimestamp()
local _, requestStatus = webhook:SendMessage(nil, { embed })
if not requestStatus.Success then
warn("Request was not successful! " .. requestStatus.statusCode .. " " .. requestStatus.statusMessage)
end
end)
|
Real use example
Here's an actual example of how Voyager can be used in a live game.
examples/gamepassPurchaseNotification.server.lua |
---|
| local marketplaceService = game:GetService("MarketplaceService")
local voyager = require(game:GetService("ServerStorage").voyager)
local webhook = voyager.Webhook.new("webhookId", "webhookToken")
marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player : Player, gamepassid : number, wasPurchased : boolean)
if not wasPurchased then return end
local gamepassInfo = marketplaceService:GetProductInfo(gamepassid, Enum.InfoType.GamePass)
local embed = voyager.Embed.new()
:SetColor(Color3.fromRGB(85, 255, 127))
:SetTimestamp()
:SetAuthor(
player.DisplayName .. " has purchased " .. gamepassInfo.Name,
"https://www.roblox.com/users/" .. player.UserId .. "/profile"
)
:AddField(
"Gamepass Price",
"**" .. gamepassInfo.PriceInRobux .. "** Robux"
)
:AddField(
"Earnings (70%)",
"**" .. (gamepassInfo.PriceInRobux * .7) .. "** Robux"
)
:AddField(
"From Game",
"[Game Link](https://www.roblox.com/games/" .. game.PlaceId .. ")"
)
local _, requestStatus = webhook:SendMessage(nil, { embed })
if not requestStatus.Success then
warn("Request was not successful! " .. requestStatus.StatusCode .. " " .. requestStatus.StatusMessage)
end
end)
|