Messages & channels ​
Sending messages ​
A message is a string, an embed-like table, or a full message:
lua
exports.np_discord:SendMessage('admin-log', 'Server restarted')
exports.np_discord:SendMessage('admin-log', { -- embed shorthand
title = 'Player banned', description = 'RDM in the safe zone', colour = 'red', timestamp = true,
fields = { { 'Player', 'Aiden', true }, { name = 'By', value = 'Admin', inline = true } },
footer = 'np_admin', thumbnail = 'https://…/avatar.png',
})
exports.np_discord:SendMessage('applications', { -- full message
content = 'New application from <@175928847299117063>', mentions = true,
embeds = { { title = 'Police', description = '…' } },
buttons = { { id = 'app:accept:42', label = 'Accept', style = 'success' }, { label = 'Rules', url = 'https://…' } },
files = { { name = 'answers.txt', content = '…' } },
reply = '1234567890123456789',
})
- Nothing pings anyone by default. Player-written text can never
@everyone. Setmentions = true(or your ownallowed_mentions) on messages that should ping. Wrap player text inEscapeMarkdownif it must not format either. - Text is cut to Discord's limits (content 2000, title 256, description 4096, 25 fields, 10 embeds) instead of being rejected.
colour: a number,'#RRGGBB',{ r, g, b }or a name (blurple green yellow red orange blue purple grey dark white).- Fields can be
{ name, value, inline }or the short form{ 'Name', 'Value', inline }. filescarry text content (logs, exports, JSON). FiveM's HTTP client is text only, so binary uploads are not possible.- Buttons with an
idare answered by anOnComponenthandler; buttons with aurlare links. channelis a config name, an id, the channel's Discord name or'guild/name'. A channel listed under a guild inConfig.Guildsposts in that guild.
DMs: SendDM(user, message) takes the same message shapes. It fails with code 50007 when the user blocks DMs.
| Export | Returns | |
|---|---|---|
SendMessage(channel, message, guild?) |
message | |
SendEmbed(channel, embed, guild?) |
message | |
EditMessage(channel, messageId, message, guild?) |
message | |
DeleteMessage(channel, messageId, reason?, guild?) |
true |
|
BulkDeleteMessages(channel, messageIds, reason?, guild?) |
true |
2 – 100 messages, none older than 14 days |
GetMessage(channel, messageId, guild?) |
message | |
GetMessages(channel, opts?, guild?) |
messages | opts = { limit ≤ 100, before, after, around }, newest first |
CrosspostMessage(channel, messageId, guild?) |
message | Publishes an announcement |
PinMessage / UnpinMessage(channel, messageId, reason?, guild?) |
true |
|
GetPinnedMessages(channel, guild?) |
messages | |
AddReaction(channel, messageId, emoji, guild?) |
true |
'👍', 'name:id' or '<:name:id>' |
RemoveReaction(channel, messageId, emoji, user?, guild?) |
true |
Without user: the bot's own |
ClearReactions(channel, messageId, emoji?, guild?) |
true |
|
GetReactions(channel, messageId, emoji, opts?, guild?) |
users |
Channels and threads ​
lua
local channel = exports.np_discord:CreateChannel({
name = 'case-1042', type = 'text', parent = 'Cases', topic = 'Robbery at the Fleeca',
permissions = {
{ id = 'everyone', type = 'role', deny = { 'VIEW_CHANNEL' } },
{ id = 'police', type = 'role', allow = { 'VIEW_CHANNEL', 'SEND_MESSAGES' } },
},
}, 'New case')
- Permission overwrites take roles and members by name (
'police','everyone', a player source) and permission names instead of bitfields. type:'text','voice','category','announcement','stage'or'forum'.EditChanneltakes the same keys;parent = falsemoves a channel out of its category.StartThread(channel, { name, autoArchive, private, message })branches a thread, from a message ifmessageis set.CreateForumPost(channel, { name, message, tags })opens a post in a forum channel.
Needs Manage Channels (and Manage Roles for overwrites). The full list is in Exports → Channels and threads.
Invites, scheduled events and emojis ​
lua
local invite = exports.np_discord:CreateInvite('welcome', { maxAge = 3600, maxUses = 1, unique = true })
print(invite.url)
exports.np_discord:CreateScheduledEvent({
name = 'Car meet', description = 'Bring your best build', start = os.time() + 86400,
finish = os.time() + 90000, location = 'Legion Square',
})
local emoji = exports.np_discord:GetEmoji('lspd') -- '<:lspd:123…>', ready to paste into a message
- Scheduled event times are unix seconds or ISO strings. Use
locationfor an event outside Discord orchannel = voice channelfor one in voice.EditScheduledEventwithstatus2 starts, 3 ends, 4 cancels it. - Emojis are kept in memory with the roles.
CreateEmojitakes a data uri.
See Exports → Invites, Scheduled events and Emojis.
Helpers ​
No request is made by any of these.
lua
local when = exports.np_discord:Timestamp(os.time() + 600, 'R') -- '<t:…:R>' shows "in 10 minutes"
local safe = exports.np_discord:EscapeMarkdown(playerText) -- no formatting, mentions or links
local ping = exports.np_discord:MentionRole('police') -- '<@&id>'
Colour, MentionUser, MentionChannel, SnowflakeTime, PermissionBits and PermissionNames are in
Exports → Helpers, together with Request for any endpoint without its own function.