Skip to main content

Events

Events to listen to on the server to utilize with third party integrations with Wasabi Chat (wasabi_chat).


info

These are server-only events. Listen with AddEventHandler in a server script. Clients cannot trigger them.

Server events​

wasabi_chat:messageSent

Fired once after each chat message is delivered. Intended for your own chat logs.

Included

  • Player messages in every channel (local, ooc, staff, groups, modes)
  • System messages (addMessage, join/leave, automatic messages)
  • Messages from exports (sendMessage, sendToJob, sendNearby)
  • Announcements (also sendAnnouncement)

Not included

  • Wrist Link DMs, unless messageLog.logDirectMessages = true in config/server/config.lua (channel 'dm')
  • The MOTD, client-only messages (client exports, TriggerClientEvent('chat:addMessage')), and the private /wristlinkresetpw reply
  • Messages canceled by a message hook, a mode callback, or the chatMessage event
AddEventHandler('wasabi_chat:messageSent', function(entry)
print(('[%s] %s: %s'):format(entry.channel, entry.name, entry.text))
end)
FieldTypeDescription
idnumberMessage ID.
channelstringTab the message shows in: 'local', 'ooc', 'staff', 'group', 'system', 'announcement', or 'dm'.
typestring'player', 'system', 'custom', or 'announcement'.
sourcenumber?Server ID of the author, or nil.
namestringPlayer name or sender label.
textstringMessage text.
imagestring?Image URL, or nil.
bannerstring?Banner file name or URL, or nil.
groupIdstring?Group ID for group messages (channel 'group').
modestring?Chat mode name for mode messages.
kindstring?'me', 'do', 'roll', 'try', or 'custom' for bubble lines in the Local tab; otherwise nil.
mentionstable?List of mentioned server IDs, or nil.
mentionTokenstable?{ { token = '@John_Doe', id = 12 } } as written, or nil.
mentionAllboolean?true for @everyone / @here, or nil.
recipientsnumberNumber of players who received the message.
resourcestring?Resource that called the export, or nil.
timestampnumberUnix time in seconds.

Discord webhook example

Wasabi Chat already includes a built-in Discord chat log (discordLogs in config/server/config.lua). If you want your own, put the webhook link in server.cfg, not in your code:

set my_chat_log_webhook "https://discord.com/api/webhooks/..."
local webhook = GetConvar('my_chat_log_webhook', '')

AddEventHandler('wasabi_chat:messageSent', function(entry)
if webhook == '' then return end

local who = entry.source and ('%s (%d)'):format(entry.name, entry.source) or entry.name

PerformHttpRequest(webhook, function() end, 'POST', json.encode({
username = 'Chat Log',
content = ('[%s/%s] %s: %s%s'):format(entry.type, entry.channel, who, entry.text, entry.image and (' ' .. entry.image) or ''),
allowed_mentions = { parse = {} },
}), { ['Content-Type'] = 'application/json' })
end)
warning

Keep allowed_mentions = { parse = {} } so player messages cannot ping @everyone or roles in your Discord. Wrist Link DMs are private: if you turn on messageLog.logDirectMessages, tell your players.

wasabi_chat:playerMuted

Fired when a player is muted with /mute or the mutePlayer export. It is not fired when a mute runs out.

AddEventHandler('wasabi_chat:playerMuted', function(entry)
print(('%s muted %s for %s minute(s): %s'):format(entry.by, entry.targetName, entry.minutes or 'unlimited', entry.reason or 'no reason'))
end)
FieldTypeDescription
targetnumber?Player server ID, or nil for an offline unmute.
targetNamestring?Player name.
identifierstring?Identifier the mute is stored under (license first).
bystring?Staff name, 'Console', or the resource name.
bySourcenumber?Staff server ID, or nil.
minutesnumber?Length in minutes; nil means until unmuted.
reasonstring?Mute reason.
expiresAtnumber?Unix time in seconds, or nil.
persistentbooleantrue when the mute is saved in the database.
wasabi_chat:playerUnmuted

Fired when a player is unmuted with /unmute or the unmutePlayer export. Provides the same data as wasabi_chat:playerMuted, except minutes and expiresAt are nil and reason is the reason of the removed mute.

AddEventHandler('wasabi_chat:playerUnmuted', function(entry)
print(('%s was unmuted by %s'):format(entry.targetName or entry.identifier, entry.by or '?'))
end)
wasabi_chat:messageFiltered

Fired each time the word filter censors or blocks a message.

AddEventHandler('wasabi_chat:messageFiltered', function(entry)
print(('%s (%s) in %s: %s'):format(entry.name, entry.source, entry.channel, table.concat(entry.words, ', ')))
end)
FieldTypeDescription
sourcenumberPlayer server ID.
namestring?Player name.
channelstring'local', 'ooc', 'staff', 'groups', 'dm', or 'bubbles'.
textstringOriginal text.
wordstableMatched list entries or patterns.
actionstring'censor' or 'block'.
filteredstring?Censored text, or nil when blocked.

Stock chat events​

These work as they do with the stock chat:

  • TriggerClientEvent('chat:addMessage', ...), chatMessage, chat:addSuggestion(s), chat:removeSuggestion, chat:addMode / chat:removeMode, and chat:clear.
  • The server still raises the chatMessage event for player messages. Cancelling it drops the message silently, like the stock chat.
AddEventHandler('chatMessage', function(source, name, message)
if message:find('discord.gg') then
CancelEvent()
end
end)
info

chat:addTemplate is ignored on purpose, because HTML is not shown.