Webhooks & logs ​
Log ​
exports.np_discord:Log('admin', { title = 'Vehicle spawned', description = '`adder`', colour = 'orange', player = source })
Log(channel, entry) queues the entry and returns at once. Every Config.Logs.flushInterval (2000 ms) the queue of
each channel is sent, ten embeds per message, so a busy log stays inside Discord's rate limits.
entryis a string, an embed or a full message (content,embeds,buttons,files). Full messages are sent on their own, in order.player = sourcein an embed adds a first field with the player's name, server id and Discord mention.- Embeds get a timestamp unless you set
timestamp = false. - Each channel keeps at most
Config.Logs.maxQueue(200) entries; the oldest are dropped first. - With
Config.Logs.enabled = false,Logreturnsfalseand sends nothing. - A channel without a destination returns
false, err(invalid_channel) and is reported once in the console.
Log channels ​
A log name is resolved to a destination in this order:
- a webhook url in the convar
discord_webhook_<name>; - a webhook url written in
Config.Logs.channels[name](don't commit it); - a bot channel:
Config.Logs.channels[name]as aConfig.Channelsname or a channel id; - with no entry in
Config.Logs.channels, aConfig.Channelsname equal to the log name.
'convar' as the value in Config.Logs.channels documents that the url comes from the convar.
Config.Logs.channels = {
joins = 'convar', -- set discord_webhook_joins "https://discord.com/api/webhooks/…"
admin = 'admin-log', -- the bot posts in Config.Channels['admin-log']
}
set discord_webhook_joins "https://discord.com/api/webhooks/…"
set discord_webhook_prison "https://discord.com/api/webhooks/…" # np_prison's log channel
Webhooks post without the bot token and keep working while the bot lacks permissions in that channel. Bot channels need
Send Messages and Embed Links. Config.Logs.username and avatar override the webhook's name and avatar.
Built-in logs ​
Config.Logs.auto maps an event to a log channel name. nil (or '') is off.
| Key | Logs | Needs |
|---|---|---|
join |
A player joined | |
leave |
A player left, with the drop reason | |
chat |
Every chat message | chat |
death |
A player died, or was killed by another player | baseevents |
resource |
A resource started or stopped |
Changes apply live, also from np_admin. The death log is the exception: np_discord only listens to the baseevents client events when the death log is on at start, so switching it on or off needs a restart.
Logs from other resources ​
np_* resources send their own records through Log when np_discord runs. The log channel names they use:
| Resource | Log channel |
|---|---|
| np_admin | Whatever Config.Logs.discord maps each audit category to (e.g. admin, reports) |
| np_prison | prison (np_discord.logChannel in shared/config/integrations.lua) |
| np_shops | shops (Config.Logs.channel) |
| np_flightradar | Config.Emergency.discordChannel |
Webhooks ​
webhook is a webhook url or { id, token }. Only Discord's own hosts are accepted. Webhook calls do not use the bot
token.
exports.np_discord:ExecuteWebhook(GetConvar('my_webhook', ''), { title = 'Hello', colour = 'green' }, { username = 'Dispatch' })
| Export | Returns | |
|---|---|---|
ExecuteWebhook(webhook, message, opts?) |
true | message |
opts = { wait, thread, username, avatar }; wait = true returns the message |
EditWebhookMessage(webhook, messageId, message, opts?) |
message | |
DeleteWebhookMessage(webhook, messageId, opts?) |
true |
|
CreateWebhook(channel, name, avatar?, reason?, guild?) |
webhook | Includes url. Treat it like a password |
GetChannelWebhooks(channel, guild?) |
webhooks | |
GetGuildWebhooks(guild?) |
webhooks | |
EditWebhook(webhookId, data, reason?) |
webhook | |
DeleteWebhook(webhookId, reason?) |
true |