how to send messages to a discord server FROM ROBLOX

Опубликовано: 16 Июль 2026
на канале: 0gagaer6
1,839
22

This Roblox Studio script uses the `HttpService` and `Players` services to send messages to a Discord webhook when a player enters a specific chat command in the game. Here's a step-by-step explanation of how the script works:

1. Services Initialization:

local httpService = game:GetService("HttpService")
local players = game:GetService("Players")
local webhook = "  / discord  "

`httpService` is used to handle HTTP requests.
`players` is used to interact with player objects.
`webhook` is the Discord webhook URL where the messages will be sent.

2. PlayerAdded Event:

players.PlayerAdded:Connect(function(player)

This event fires whenever a new player joins the game.
`player` is the new player object that just joined.

3. Player Chatted Event:
player.Chatted:Connect(function(message)
This event fires whenever the player sends a chat message.
`message` is the content of the chat message.

4. Check for Command Prefix:

if string.sub(message, 1, 5) == "/send" then

The script checks if the first 5 characters of the message are "/send".
If the message starts with "/send", it processes the command.

5. Extract Command Parameter:

local commandpara = string.sub(message, 7)
print(commandpara)

The script extracts the part of the message following the command prefix "/send ".
`commandpara` holds this extracted text.
`print(commandpara)` outputs this text to the console for debugging purposes.

6. Prepare Data for Webhook:

local data = {
content = commandpara,
username = player.Name
}

local jsonData = httpService:JSONEncode(data)

`data` is a table containing the `content` (command parameter) and `username` (player's name).
`httpService:JSONEncode(data)` converts the `data` table into a JSON string.

7. Send Data to Webhook:

httpService:PostAsync(webhookURL, jsonData, Enum.HttpContentType.ApplicationJson)

`httpService:PostAsync` sends an HTTP POST request to the specified `webhookURL`.
The JSON data (`jsonData`) is sent in the request body.
`Enum.HttpContentType.ApplicationJson` specifies that the content type of the request is JSON.

Overall, the script listens for players joining the game and their chat messages. If a message starts with "/send", it extracts the rest of the message and sends it, along with the player's username, to a Discord webhook.

note that the game has to be uploaded to roblox and http requests have to be allowed. to allow http requests open up game settings, go to security, then select allow http services