Your browser does not support JavaScript or its disabled!
Please turn it on, or be aware that some features on this website will not work correctly.
2.4K
Discord Webhook #96
This will allow you to send Webhook messages to a discord server.
I have no plans to help you set it up.
If you find a bug let me know.
File: discord.lua | 1.72kb | 66 lines.
 --[[
  Script made by Lee (Discord: l33_) - www.trainorcreations.com
  If you want to support my work, feel free to donate at https://trainorcreations.com/donate
  PS. Stop ripping off my work and selling it as your own.
 ]]--
local discordTimes = {}
 -- insert your webhook link below
local webhook = "https://discord.com/api/webhooks/"

local default_data = {
  username = "LeeBot", -- name discord displays the message from
}

local embed = {
  color = 10038562, -- default color - dark red
  footer = { -- remove this if you don't want a footer.
      ["text"] = "Thanks Lee",
  },
}

function onHTTPResult(data, err)
  if err then
    print("Discord Webhook Error: ".. err)
  end
end

 -- This allows you to send messages to discord using a webhook.
 -- The "id" is to save the time it was last used and the "delayed" is the next time it can send (Player alert beeps every 1500ms, you can make it so it only sends the alert once every 10 seconds etc.)
function sendDiscordWebhook(data)
local id = data.id
  if id then
    local dTime = discordTimes[id]
    if dTime and os.time() < dTime then return end
    discordTimes[id] = os.time() + (data.delayed and data.delayed or 10) -- delayed value or 10 seconds
  end

  local dEmbed = embed
  if data.color then dEmbed.color = data.color end
  dEmbed.title = "**".. data.title .."**"
  dEmbed.fields = {
    {
      name = "Name: ",
      value = data.name,
    },
    {
      name = "Message",
      value = data.message,
    }
  }

  local dataSend = default_data
  dataSend.embeds = { dEmbed }
  HTTP.postJSON(webhook, dataSend, onHTTPResult)
end

 --------------
 -- example --
 --------------
UI.Separator()
UI.Label("Discord Webhook")
UI.Button("Example 1", function()
  local data = {
   title = 'Player Detection',
   name = 'Lee',
   message = 'Leed - Player Detected!',
   id = "pd",
   delayed = 60, -- 60 seconds
  }
  sendDiscordWebhook(data)
end)
UI.Separator()

14 May 2022
Ads