Advertisement
ahmad1218

roblox chat logger to webhook

May 25th, 2023
1,926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | Source Code | 0 0
  1. getgenv().webhookUrl = "" -- put your discord webhook in ""
  2. local http_request = http_request or request or HttpPost or syn.request
  3.  
  4. local function sendToWebhook(message)
  5.     local data = {
  6.         content = message
  7.     }
  8.  
  9.     local headers = {
  10.         ["Content-Type"] = "application/json"
  11.     }
  12.  
  13.     local webhookUrl = getgenv().webhookUrl
  14.     if not webhookUrl then
  15.         print("webhookUrl is not set.")
  16.         return
  17.     end
  18.  
  19.     local success, response = pcall(function()
  20.         return http_request({
  21.             Url = webhookUrl,
  22.             Method = "POST",
  23.             Headers = headers,
  24.             Body = game:GetService("HttpService"):JSONEncode(data)
  25.         })
  26.     end)
  27.  
  28.     if success then
  29.         print("Message sent to Discord webhook!")
  30.     else
  31.         print("Failed to send message to Discord webhook. Error: " .. response)
  32.     end
  33. end
  34.  
  35. -- Event handler for chat messages
  36. local function onPlayerChatted(message)
  37.     sendToWebhook(message)
  38. end
  39.  
  40. game.Players.LocalPlayer.Chatted:Connect(onPlayerChatted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement