Sending Discord Webhooks through TextLabels

I have been trying to make it so when you write text and you submit it, it arrives to Discord through a webhook in text form. Any help on how I should do it?

1 Like

Hi, you’ve not posted any code that you have made, or given us any reference of where you are. Our job is to help, not create this system for you. You’ll need to use either a pre-created library for Discord to send webhook messages, or look and create your own message sending system by looking at their documentation here.

Good luck!

You can send a message to a Discord webhook with HttpService:PostAsync().

It is recommended to use RequestAsync. HttpService | Documentation - Roblox Creator Hub

I do believe PostAsync was changed to use this when it released.

Have you made any attempt at looking at any documentation? That would help you.

local HttpService = game.GetService(game, 'HttpService');
local WebhookUrl = '';

local data = HttpService.JSONEncode(HttpService, {
    content = 'Some string',
    username = 'Override the current username',
    avatar_url = 'Override the current avatar',
    tts = 'Should the message be a Text To Speech Message',
    file = 'Send a file',
    embeds = {
        {
            title = 'some title',
            type = 'Always `rich`',
            description = 'some description',
            ... -- Not bothered to fill the rest,
                -- Refer to https://discord.com/developers/docs/resources/channel#embed-object
        }
    }, -- This is an array 
    payload_json = 'See https://discord.com/developers/docs/resources/channel#create-message',
    allowed_mentions = 'allowed mentions for the message'
})

HttpService.PostAsync(HttpService, WebhookUrl, data, Enum.HttpContentType.ApplicationJson)

You can it.

  1. Create a RemoteEvent in ReplicatedStorage. Name it “WebhookService

  2. In a Script located in ServerScriptService put this:
    local HttpService = game:GetService(“HttpService”)
    local WebhookURL = “” – Here, put the Discord Webhook URL.

    local function postToDiscord(Message)
    local Data = {
    [“content”] = Message
    }
    Data = HttpService:JSONEncode(Data)
    HttpService:PostAsync(WebhookURL, Data)
    end

    game.ReplicatedStorage.WebhookService.OnServerEvent:Connect(function(Player, TextContent)
    postToDiscord("") --Here, post the body of message. Example "The user " … Player.Name … " sended the following message: " … TextContent
    end)

  3. Create a LocalScript in the TextBox from which the message will be sent with the following content:
    local Plr = game.Players.LocalPlayer
    local BtnSend = --here the location of your send button

    local MessageBox = --here the location of your textbox
    BtnSend.MouseButton1Click:Connect(function(hit)
    local TextContent = MessageBox.Text
    local Player = game.Players.LocalPlayer
    game.ReplicatedStorage.WebhookService:FireServer(TextContent)
    end)

This is how the system works:

I hope it helps you, greetings.

3 Likes

Please put your code in a code block next time.

There are two issues within the code you shared.

  1. You are not filtering the messages before sending them to Discord.
  2. You have no cooldown, so an exploiter can spam the remote and have your ebook deleted.
1 Like

Oh, is my first time using the code blocks. Sorry

  1. I maked the script with the purpose for send feedback in a small game that kept 2 average players a week. But, is possible filtering the system, replacing the script in ServerScriptService to:

local HttpService = game:GetService(“HttpService”)
local WebhookURL = “” – Here, put the Discord Webhook URL.

local function postToDiscord(Message)
local Data = {
[“content”] = Message
}
Data = HttpService:JSONEncode(Data)
HttpService:PostAsync(WebhookURL, Data)
end

game.ReplicatedStorage.WebhookService.OnServerEvent:Connect(function(Player, TextContent)
local textFiltered = game:GetService("Chat"):FilterStringForBroadcast(textFiltered, Player)
postToDiscord("") --Here, post the body of message. Example "The user " … Player.Name … sended the following message: " … textFiltered
end)
  1. You can set a cooldown in the LocalScript before the FireServer like 2 seconds using wait() expresion. Example:
    wait(3)
    game.ReplicatedStorage.WebhookService:FireServer(TextContent)

A wait() is not a cooldown; it will just delay all requests by three seconds.

In some cases wait works to skip spamming in this messages, that delay all requests.

Adding a wait() is the same without a wait(); you are just executing the action 3 seconds later.