Events
Events to listen to on the server to utilize with third party integrations with Wasabi Chat (wasabi_chat).
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 = trueinconfig/server/config.lua(channel'dm') - The MOTD, client-only messages (client exports,
TriggerClientEvent('chat:addMessage')), and the private/wristlinkresetpwreply - Messages canceled by a message hook, a mode callback, or the
chatMessageevent
AddEventHandler('wasabi_chat:messageSent', function(entry)
print(('[%s] %s: %s'):format(entry.channel, entry.name, entry.text))
end)
| Field | Type | Description |
|---|---|---|
id | number | Message ID. |
channel | string | Tab the message shows in: 'local', 'ooc', 'staff', 'group', 'system', 'announcement', or 'dm'. |
type | string | 'player', 'system', 'custom', or 'announcement'. |
source | number? | Server ID of the author, or nil. |
name | string | Player name or sender label. |
text | string | Message text. |
image | string? | Image URL, or nil. |
banner | string? | Banner file name or URL, or nil. |
groupId | string? | Group ID for group messages (channel 'group'). |
mode | string? | Chat mode name for mode messages. |
kind | string? | 'me', 'do', 'roll', 'try', or 'custom' for bubble lines in the Local tab; otherwise nil. |
mentions | table? | List of mentioned server IDs, or nil. |
mentionTokens | table? | { { token = '@John_Doe', id = 12 } } as written, or nil. |
mentionAll | boolean? | true for @everyone / @here, or nil. |
recipients | number | Number of players who received the message. |
resource | string? | Resource that called the export, or nil. |
timestamp | number | Unix 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)
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)
| Field | Type | Description |
|---|---|---|
target | number? | Player server ID, or nil for an offline unmute. |
targetName | string? | Player name. |
identifier | string? | Identifier the mute is stored under (license first). |
by | string? | Staff name, 'Console', or the resource name. |
bySource | number? | Staff server ID, or nil. |
minutes | number? | Length in minutes; nil means until unmuted. |
reason | string? | Mute reason. |
expiresAt | number? | Unix time in seconds, or nil. |
persistent | boolean | true 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)
| Field | Type | Description |
|---|---|---|
source | number | Player server ID. |
name | string? | Player name. |
channel | string | 'local', 'ooc', 'staff', 'groups', 'dm', or 'bubbles'. |
text | string | Original text. |
words | table | Matched list entries or patterns. |
action | string | 'censor' or 'block'. |
filtered | string? | 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, andchat:clear.- The server still raises the
chatMessageevent 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)
chat:addTemplate is ignored on purpose, because HTML is not shown.