OpenTibiaBR
GithubDiscordSponsor
  • Home
    • 📖Welcome!
    • 💵Donate
  • OpenTibiaBR
    • 🖥️Projects
      • 🐦Canary
        • About
        • Getting Started
          • Compiling
            • Linux
              • [Linux] Compiling Canary Sources
            • Windows
              • Visual Studio
                • [Windows][VC2022][CMake] Compiling Canary Sources
                • [Windows][VC2022][Solution] Compiling Canary Sources
              • WSL
                • [WSL] Compiling Canary Sources
          • Installing
            • aaPanel
              • [Linux] Canary + aaPanel + MyAAC
            • Docker
              • [Docker] Canary + MariaDB + MyAAC
            • Linux
              • Nginx + MariaDB + MyAAC
            • Windows
              • Uniform Server
                • [Windows][Basic] Canary + Uniform Server + MyAAC
              • XAMPP
                • [Windows][Advanced] Canary + XAMPP + MyAAC
        • Tutorials
          • Basic
            • Auto Backup Server Database
            • Auto Restart and Linux Logs
            • Custom Bestiary / Prey with Canary Monster Editor
            • Event Schedule Canary / OTServBR-Global
            • How to make a custom server with Canary
            • How to reset players in your database
            • How to secure a Linux server
            • SSL Certificates
            • Webhook Discord
            • [Outdated] Custom Bestiary / Prey
            • [Linux] Backup + Upload - Google Drive
            • [Linux] How to install Linux headers
            • VPS Linux
            • [Windows] SSL/HTTPS Certificate with XAMPP
          • Mapping
            • [Windows] Remere's Map Editor - Opening Canary / OTServBR-Global Map
            • [Windows] Remere's Map Editor - Converting map server id to client id
          • Programming & Scripting
            • How to add a new vocation
            • Revscriptsys
            • Guide Lua Objects
            • How to get raceId for monsters
          • Websites
            • [Canary][OTServBR-Global][GesiorAAC][MyAAC] Set up Initial Character
          • Miscellaneous
            • Useful Tutorials
            • Video Tutorials
      • 🗺️Remere's Map Editor
        • About
        • Getting Started
          • Linux
            • [Linux] Compiling Remere's Map Editor Sources
          • Windows
            • WSL
              • [WSL] Compiling Remere's Map Editor Sources
            • Visual Studio
              • [Windows][VC2022][CMake] Compiling Remere's Map Editor Sources
              • [Windows][VC2022][Solution] Compiling Remere's Map Editor Sources
      • 🎮OTClient Redemption
        • About
        • Getting Started
          • Android
            • [Android] Compiling OTClient Redemption Sources
          • Linux
            • [Linux] Compiling OTClient Redemption Sources
          • Windows
            • WSL
              • [WSL] Compiling OTClient Redemption Sources
            • Visual Studio
              • [Windows][VC2022][CMake] Compiling OTClient Redemption Sources
              • [Windows][VC2022][Solution] Compiling OTClient Redemption Sources
          • Web
            • [Web] OTClient Redemption
        • Tutorials
          • Basic
            • Client Updater
    • 🔗Downloads
      • 🎮Clients
        • Client 11
        • Client 14
          • Tutorials
            • Client with HexEditorXVI32
            • Client with Notepad++
            • Client with config.ini
            • [Windows] How to change client background
        • OTClientV8
          • About
          • Getting Started
            • Android
              • [Android] Compiling OTClientV8 Sources
            • Linux
              • [Linux] Compiling OTClientV8 Sources
            • Windows
              • WSL
                • [WSL] Compiling OTClientV8 Sources
              • Visual Studio
                • [Windows][VC2022][CMake] Compiling OTClientV8 Sources
                • [Windows][VC2022][Solution] Compiling OTClientV8 Sources
          • Features
            • Health and Mana bar backgrounds
            • HTTP support
            • OTML Improvement
            • Simple cam recorder and player
            • Updater, encryption and compression
            • WebSockets
        • Minimap
      • 📑Codes
        • C++
        • Events
        • Functions
        • Libs
        • Modules
        • Others
      • 🖼️Images
        • PSDs
        • Others
      • 🗺️Maps
        • Custom
        • Global
      • 📑Revscripts
        • Actions
        • CreatureEvents
        • GlobalEvents
        • MoveEvents
        • NPCs
        • Spells
        • Systems
        • TalkActions
      • ⚔️Sprites
      • ⚙️Tools
        • Editors
        • Launchers
          • Canary Launcher
            • About
            • Getting Started
              • Windows
                • [Windows][VC2022][Solution] Compiling Canary Launcher Sources
          • Slender Launcher
            • About
            • Getting Started
              • Windows
                • [Windows][Go] Compiling Slender Launcher Sources
        • Login Server
          • About
          • Getting Started
        • Map Generators
      • 🌐Web Packages
        • Linux
        • Windows
      • 🌐Website Applications
        • Websites
          • CanaryAAC
            • About
            • Informations
              • Features
              • Functions
              • API
              • Routes
              • Middleware
            • CanaryAAC Bot
          • Gesior2012
            • About
          • GesiorAAC Global
            • About
          • MyAAC
            • About
          • MyAAC Global
            • About
          • SlenderAAC
            • About
          • ZnoteAAC
            • About
        • Applications
        • Layouts
        • APIs and SDKs
Powered by GitBook
On this page
  • Tutorial to help set up the discord webhook.
  • 1 - Configuration - Discord:
  • 2 - Configuration - Server:
  • 3 - Result:
  • 4 - Additional Information:
  • 5 - Special Webhooks:
  • Examples:
  1. OpenTibiaBR
  2. Projects
  3. Canary
  4. Tutorials
  5. Basic

Webhook Discord

Last updated 11 months ago

Tutorial to help set up the discord webhook.

It has notification functions to start, save, shut down, and raids.

Credits:

wizardlink (Discord Webhook)

Majesty (Tutorial)

1 - Configuration - Discord:

  • Create a server in Discord for your project/community.

  • Access the server configuration:

  • Access Integrations, Webhooks and click the Create webhook button:

  • Set up a name for the webhook and channel for notifications:

  • Copy the webhook URL.

2 - Configuration - Server:

  • Open the file config.lua / config.lua.dist server OTServBR-Global.

  • Look for:

-- Sends Discord webhook notifications on startup, raids and shutdown.
-- The URL layout is https://discord.com/api/webhooks/:id/:token
-- Leave empty if you wish to disable.
discordWebhookURL = ""
  • Add the URL of your webhook, example:

-- Sends Discord webhook notifications on startup, raids and shutdown.
-- The URL layout is https://discord.com/api/webhooks/:id/:token
-- Leave empty if you wish to disable.
discordWebhookURL = "https://discord.com/api/webhooks/811627385782403083/6hrWa2Aq38i4Ct17_l4D1mTr6YZjYRplKrvUYkvV6OuoPHDiJoi8bxPdcjTik4scQu37"

3 - Result:

4 - Additional Information:

  • The webhook system comes pre-installed in OTServBR-Global for various functions such as save, close, intrusions, etc., but is fully flexible to use in any type of notification that you would like your users to receive on your discord server. It runs with the function:

Webhook.send("Title", "message", WEBHOOK_COLOR_WARNING)

The color can also be changed, the ones available in OTServBR-Global are as follows (with possibility of expansion):

enum Webhook_Colors_t : uint32_t {
    WEBHOOK_COLOR_ONLINE = 0x00FF00,
    WEBHOOK_COLOR_OFFLINE = 0xFF0000,
    WEBHOOK_COLOR_WARNING = 0xFFFF00,
    WEBHOOK_COLOR_RAID = 0x0000FF
};

5 - Special Webhooks:

  • With this you configure channels webhooks in discord and paste the discord api url in this file:

-- Sends Discord webhook special notifications.
-- The URL layout is https://discord.com/api/webhooks/:id/:token
-- Leave empty if you wish to disable.

announcementChannels = {
    ["serverAnnouncements"] = "", -- Used for an announcement channel on your discord
    ["raids"] = "", -- Used to isolate raids on your discord
    ["player-kills"] = "", -- Self-explaining
}

-- Example of notification (After you do the config):
-- Webhook.send("Server save", message, WEBHOOK_COLOR_WARNING, announcementChannels["serverAnnouncements"]) -- This is going to send a message into your server announcements channel

--[[ 
	Dev Comment: This lib can be used to add special webhook channels 
	where you are going to send your messages. Webhook.specialSend was designed
	to be used with countless possibilities.	
]]

Examples:

Broadcast:

local broadcast = TalkAction("/b")
function broadcast.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    if param == "" then
        player:sendCancelMessage("Command param required.")
        return false
    end

    print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".")
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
    end    
   Webhook.send(player:getName().." has broadcasted", param, WEBHOOK_COLOR_WARNING, announcementChannels["serverAnnouncements"])
return false
end

broadcast:separator(" ")
broadcast:register()

OpenServer:

local openServer = TalkAction("/openserver")

function openServer.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

Game.setGameState(GAME_STATE_NORMAL)     
player:sendTextMessage(MESSAGE_ADMINISTRADOR, "Server is now open.")
Webhook.send("Server Open", "Server is now open", WEBHOOK_COLOR_ONLINE, announcementChannels["serverAnnouncements"])
    return false
end

openServer:separator(" ")
openServer:register()

Ban:

local banDays = 7

local ban = TalkAction("/ban")

function ban.onSay(player, words, param)

	if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
		return true
	end

	if param == "" then
		player:sendCancelMessage("Command param required.")
		return false
	end

	local name = param
	local reason = ''

	local separatorPos = param:find(',')
	if separatorPos then
		name = param:sub(0, separatorPos - 1)
		reason = string.trim(param:sub(separatorPos + 1))
	end

	local accountId = getAccountNumberByPlayerName(name)
	if accountId == 0 then
		return false
	end

	local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
	if resultId ~= false then
		result.free(resultId)
		return false
	end

	local timeNow = os.time()
	db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
			accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")")

	local target = Player(name)
	if target then
		player:sendTextMessage(MESSAGE_ADMINISTRADOR, target:getName() .. " has been banned.")
		Webhook.send(name.. " has been banned", "reason: " ..reason.. ".", WEBHOOK_COLOR_WARNING, announcementChannels["serverAnnouncements"])
		target:remove()
	else
		player:sendTextMessage(MESSAGE_ADMINISTRADOR, name .. " has been banned.")
	end
end

ban:separator(" ")
ban:register()

Player Record:

local playerrecord = GlobalEvent("playerrecord")
function playerrecord.onRecord(current, old)
	addEvent(Game.broadcastMessage, 150, 'New record: ' .. current .. ' players online.', MESSAGE_EVENT_ADVANCE)
	Webhook.send("New record online", "Player count: " .. current, WEBHOOK_COLOR_ONLINE, announcementChannels["serverAnnouncements"])
	return true
end
playerrecord:register()

Update Player on Advanced Level:

local updatePlayerOnAdvancedLevel = CreatureEvent("UpdatePlayerOnAdvancedLevel")

function updatePlayerOnAdvancedLevel.onAdvance(player, skill, oldLevel, newLevel)
	if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
		return true
	end

	player:addHealth(player:getMaxHealth())
	player:addMana(player:getMaxMana())
	player:getFinalLowLevelBonus()
	player:save()
	Webhook.sendMessage(":rocket: " .. player:getMarkdownLink() .. " advanced from Level " ..  oldLevel .. " to Level " .. newLevel .. ".", announcementChannels["player-levels"])
	return true
end

updatePlayerOnAdvancedLevel:register()

🖥️
🐦