I am wondering how I can send information that a player has inputted to a discord channel through webhook. Here is the script that I’ve got to send the webhook but I don’t know how to get the information that the player has put in onto the embedded message.
local webhook = "" -- Webhook here
local http = game:GetService("HttpService")
local plr = game:GetService("Player")
local sendanswers = {
["content"] = '',
["embeds"] = {{
["title"] = "**"..plr.name.."** Answer's",
["description"] = "",
["color"] = 15636761,
}}
}
sendanswers = http:JSONEncode(sendanswers)
http:PostAsync(webhook, sendanswers)
This will be sent as soon as the submit button with all the answers in one and not as the player goes through each question.
If anyone has any ideas on how to do this, it would be greatly appreciated if someone could suggest something, just to inform you it will be done on a 1 person server.
Hm, you can always make a neat format. You could send data to the server via a remote event or something and then organize a table with the answers from there, make sure it’s less than 2000 characters (assuming that’s the limit) or if it exceeds 2k, you can probably send a webhook with the rest of the information.
Here’s an example. Sorry for the long delay, took a while to write the necessary. Check the comments I made at the end of the script.
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Webhook = "LINK_HERE"
local function GetCurrentTime()
local CurrentTime = os.date("!*t")
local Hour = CurrentTime.hour
local Minute = CurrentTime.min
local Second = CurrentTime.sec
local Day = CurrentTime.day
local Month = CurrentTime.month
local Year = CurrentTime.year
if Hour < 10 then
Hour = 0 .. Hour
end
if Minute < 10 then
Minute = 0 .. Minute
end
if Second < 10 then
Second = 0 .. Second
end
if Day < 10 then
Day = 0 .. Day
end
if Month < 10 then
Month = 0 .. Month
end
if Year < 10 then
Year = 0 .. Year
end
return ("%s-%s-%sT%s:%s:%sZ"):format(Year, Month, Day, Hour, Minute, Second)
end
local Base = [[**Username:** [%s](https://www.roblox.com/users/%s/profile)
**Game:** [%s](https://www.roblox.com/games/%s/Game)
]]
local function GetBustThumb(Player)
return ("https://www.roblox.com/bust-thumbnail/image?userId=%s&width=420&height=420&format=png"):format(Player.UserId)
end
local function GetHeadshotThumb(Player)
return ("https://www.roblox.com/headshot-thumbnail/image?userId=%s&width=420&height=420&format=png"):format(Player.UserId)
end
local function SendWebhook(Player, Data)
local Options = {}
Options.timestamp = GetCurrentTime()
Options.description = Base:format(
Player.Name or "N/A",
Player.UserId or 0,
MarketplaceService:GetProductInfo(game.PlaceId).Name,
game.PlaceId
)
Options.footer = {
icon_url = "",
text = "Form Logs"
}
Options.thumbnail = {
url = GetBustThumb(Player)
}
Options.author = {
name = Player.Name,
url = "https://www.roblox.com/users/" .. Player.UserId .. "/profile",
icon_url = GetHeadshotThumb(Player)
}
local List = ""
for i,v in pairs(Data) do
List = List .. "Question " .. i .. ") " .. v.Question .. "\n" .. "Answer: " .. v.Answer .. "\n\n"
end
Options.fields = {
{name = "RESPONSE", value = List, inline = true}
}
local HookData = {
username = Player.Name,
avatar_url = GetHeadshotThumb(Player),
embeds = {Options}
}
HookData["content"] = Player.Name .. " sent in a new response!"
local Success, Error = pcall(function()
HookData = HttpService:JSONEncode(HookData)
HttpService:PostAsync(Webhook, HookData)
end)
if not Success then
warn(tostring(Error))
end
end
--// Data \\--
local Data = {
{
Question = "Are you testing?",
Answer = "Yes!"
},
{
Question = "Should you use this?",
Answer = "Maybe."
}
}
-- The example above is the data being sent to the server. It must use that format or else it won't work, unless you change the script.
-- Use a RemoteEvent to send the data, make the client handle the Data table before sending to the server.
-- You can filter the messages to make sure players won't send NSFW responses.
While what @Avanthyst sent might answer your question, keep this in mind: Discord is not a logging service. Do not treat it as such. It’s also worth noting that Discord has blocked Roblox server requests in the past.
Hello, so when I am sending the information from the gui to the script there, should I use multiple events like 1 event per question or just 1 event all together?
Alright, thank you so much, I have just added a quick addition of
local Data = {
{
Question = "Are you testing?",
Answer = "Yes!"
},
{
Question = "Should you use this?",
Answer = Answer2
}
}
And
local rs = game.ReplicatedStorage.QuestionAns
rs.OnServerEvent:Connect(function(Answer2))
And then in the client-side script I just added this,
local RS = game.ReplicatedStorage.QuestionAns
local Answer2 = script.Parent.Parent.Answers.TextBox.Text
script.Parent.MouseButton1Click:Connect(function()
RS:FireServer(Answer2)
end)
Furthermore, I don’t really get where I can add a submit button as I can’t really seem to find the needed scripting for it. As I am not the best at scripting I don’t really know where to put it.