DiscordLua
discorddiscord
v1.2.4
Install

Utilities

Reference
On this page

Formatters

Markdown helpers also exported on the discord table (discord.bold, discord.time, discord.underscore, …).

Formatters.userMention

Signature

Formatters.userMention(id)
NameTypeRequiredBehavior
id string required Snowflake id string.

Formatters.channelMention

Signature

Formatters.channelMention(id)
NameTypeRequiredBehavior
id string required Snowflake id string.

Formatters.roleMention

Signature

Formatters.roleMention(id)
NameTypeRequiredBehavior
id string required Snowflake id string.

Formatters.slashCommandMention

Signature

Formatters.slashCommandMention(name, commandId)
NameTypeRequiredBehavior
name any required Passed through to the implementation as written.
commandId string required Snowflake id string.

Formatters.chatInputApplicationCommandMention

Signature

Formatters.chatInputApplicationCommandMention(name, a, b, c)
NameTypeRequiredBehavior
name any required Passed through to the implementation as written.
a any required Passed through to the implementation as written.
b any required Passed through to the implementation as written.
c any required Passed through to the implementation as written.

Formatters.applicationDirectory

Signature

Formatters.applicationDirectory(applicationId, skuId)
NameTypeRequiredBehavior
applicationId string required Snowflake id string.
skuId string required Snowflake id string.

Formatters.list

Signature

Formatters.list(items, options)
NameTypeRequiredBehavior
items number required Duration in milliseconds.
options table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

Formatters.orderedList

Signature

Formatters.orderedList(items, startNumber)
NameTypeRequiredBehavior
items number required Duration in milliseconds.
startNumber any required Passed through to the implementation as written.

Formatters.unorderedList

Signature

Formatters.unorderedList(items)
NameTypeRequiredBehavior
items number required Duration in milliseconds.

Formatters.formatEmoji

Signature

Formatters.formatEmoji(name, id, animated)
NameTypeRequiredBehavior
name any required Passed through to the implementation as written.
id string required Snowflake id string.
animated any required Passed through to the implementation as written.

Formatters.time

Signature

Formatters.time(seconds, style)
NameTypeRequiredBehavior
seconds any required Passed through to the implementation as written.
style any optional Passed through to the implementation as written.

Formatters.bold

Signature

Formatters.bold(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.italic

Signature

Formatters.italic(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.underline

Signature

Formatters.underline(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.strikethrough

Signature

Formatters.strikethrough(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.spoiler

Signature

Formatters.spoiler(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.inlineCode

Signature

Formatters.inlineCode(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.codeBlock

Signature

Formatters.codeBlock(languageOrText, text)
NameTypeRequiredBehavior
languageOrText any required Passed through to the implementation as written.
text any required Passed through to the implementation as written.

Formatters.quote

Signature

Formatters.quote(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.blockQuote

Signature

Formatters.blockQuote(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.hideLinkEmbed

Signature

Formatters.hideLinkEmbed(url)
NameTypeRequiredBehavior
url any required Passed through to the implementation as written.

Formatters.emoji

Signature

Formatters.emoji(name, id, animated)
NameTypeRequiredBehavior
name any required Passed through to the implementation as written.
id string required Snowflake id string.
animated any required Passed through to the implementation as written.

Formatters.escapeMarkdown

Signature

Formatters.escapeMarkdown(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeCodeBlock

Signature

Formatters.escapeCodeBlock(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeInlineCode

Signature

Formatters.escapeInlineCode(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.heading

Signature

Formatters.heading(text, level)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.
level any required Passed through to the implementation as written.

Formatters.subtext

Signature

Formatters.subtext(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeHeading

Signature

Formatters.escapeHeading(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeBulletedList

Signature

Formatters.escapeBulletedList(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeNumberedList

Signature

Formatters.escapeNumberedList(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeBold

Signature

Formatters.escapeBold(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeItalic

Signature

Formatters.escapeItalic(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeUnderline

Signature

Formatters.escapeUnderline(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeSpoiler

Signature

Formatters.escapeSpoiler(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

Formatters.escapeStrikethrough

Signature

Formatters.escapeStrikethrough(text)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

discord.util

The same helpers are also exported on the package root: discord.parseEmoji, discord.resolveColor, discord.resolveImage, discord.cleanContent, discord.fetchRecommendedShardCount, and the other names listed below.

util.class

Signature

discord.util.class(name)

Define a DiscordLua class table with callable construction and :new.

NameTypeRequiredBehavior
name any required Passed through to the implementation as written.

util.is_builder

Signature

discord.util.is_builder(value)

Predicate that returns whether this util matches is_builder. Use it to branch before calling type-specific methods.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.encode_one

Signature

discord.util.encode_one(value)

Encode a single Lua value for a REST body field.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.encode_list

Signature

discord.util.encode_list(list)

Encode an array of values for a REST body field.

NameTypeRequiredBehavior
list any required Passed through to the implementation as written.

util.is_json_null

Signature

discord.util.is_json_null(value)

Predicate that returns whether this util matches is_json_null. Use it to branch before calling type-specific methods.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.encode_message

Signature

discord.util.encode_message(contentOrOptions)

Encode a message send/edit payload for REST.

NameTypeRequiredBehavior
contentOrOptions table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

util.encode_poll_media

Signature

discord.util.encode_poll_media(media)

Encode poll question or answer media.

NameTypeRequiredBehavior
media any required Passed through to the implementation as written.

util.encode_poll_answer

Signature

discord.util.encode_poll_answer(answer)

Encode a single poll answer.

NameTypeRequiredBehavior
answer any required Passed through to the implementation as written.

util.encode_poll

Signature

discord.util.encode_poll(options)

Encode a poll object for a message payload.

NameTypeRequiredBehavior
options table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

util.resolveRoleColor

Signature

discord.util.resolveRoleColor(value)

Resolve a role color value the same way role create/edit payloads accept it.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.resolveRoleColors

Signature

discord.util.resolveRoleColors(colors)

Resolve a table of role color fields before encoding a role payload.

NameTypeRequiredBehavior
colors any required Passed through to the implementation as written.

util.encodeRoleOptions

Signature

discord.util.encodeRoleOptions(options)

Encode role create/edit options, including colors and permissions.

NameTypeRequiredBehavior
options table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

util.parse_hex

Signature

discord.util.parse_hex(text)

Parse a hex color string into a numeric color value.

NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

util.resolveCode

Signature

discord.util.resolveCode(data, pattern)

Extract an invite or template code from a URL or raw code string.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.
pattern any required Passed through to the implementation as written.

util.resolveInviteCode

Signature

discord.util.resolveInviteCode(data)

Extract a Discord invite code from a URL or raw code string.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.

util.resolveGuildTemplateCode

Signature

discord.util.resolveGuildTemplateCode(data)

Extract a guild template code from a URL or raw code string.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.

util.resolveBase64

Signature

discord.util.resolveBase64(data)

Encode binary or text input as a base64 string for REST image fields.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.

util.resolveImage

Signature

discord.util.resolveImage(image)

Turn a file path, data URI, or buffer into the image data DiscordLua sends on REST.

NameTypeRequiredBehavior
image any required Passed through to the implementation as written.

util.toSnakeCase

Signature

discord.util.toSnakeCase(text)

Convert a camelCase identifier into snake_case for REST body keys.

NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

util.flatten

Signature

discord.util.flatten(obj, props)

Flatten nested option tables before encoding a REST payload.

NameTypeRequiredBehavior
obj any required Passed through to the implementation as written.
props any required Passed through to the implementation as written.

util.parseEmoji

Signature

discord.util.parseEmoji(text)

Parse an emoji mention, unicode character, or name into a table DiscordLua can send.

NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

util.resolvePartialEmoji

Signature

discord.util.resolvePartialEmoji(emoji)

Normalize an emoji mention or id/name table into a partial emoji payload.

NameTypeRequiredBehavior
emoji any required Passed through to the implementation as written.

util.resolveGuildEmoji

Signature

discord.util.resolveGuildEmoji(guild, emoji)

Resolve a guild emoji from an id, mention, or emoji object.

NameTypeRequiredBehavior
guild any required Passed through to the implementation as written.
emoji any required Passed through to the implementation as written.

util.makeError

Signature

discord.util.makeError(data)

Construct a DiscordLua error object from a name and message.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.

util.makePlainError

Signature

discord.util.makePlainError(err)

Construct a plain error table without Discord-specific fields.

NameTypeRequiredBehavior
err any required Passed through to the implementation as written.

util.getSortableGroupTypes

Signature

discord.util.getSortableGroupTypes(channelType)

Read the SortableGroupTypes value from this util.

NameTypeRequiredBehavior
channelType any required Passed through to the implementation as written.

util.moveElementInArray

Signature

discord.util.moveElementInArray(array, element, newIndex, offset)

Move an element to a new index in a Lua array.

NameTypeRequiredBehavior
array any required Passed through to the implementation as written.
element any required Passed through to the implementation as written.
newIndex any required Passed through to the implementation as written.
offset any required Passed through to the implementation as written.

util.verifyString

Signature

discord.util.verifyString(data, errorType, errorMessage, allowEmpty)

Assert that a value is a non-empty string, or raise.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.
errorType any required Passed through to the implementation as written.
errorMessage any required Passed through to the implementation as written.
allowEmpty any required Passed through to the implementation as written.

util.resolveColor

Signature

discord.util.resolveColor(color)

Convert a color name, hex string, number, or RGB table into the integer DiscordLua encodes on REST payloads.

NameTypeRequiredBehavior
color any required Passed through to the implementation as written.

util.discordSort

Signature

discord.util.discordSort(collection)

Performs discord sort on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
collection any required Passed through to the implementation as written.

util.basename

Signature

discord.util.basename(path, ext)

Performs basename on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
path any required Passed through to the implementation as written.
ext any required Passed through to the implementation as written.

util.findName

Signature

discord.util.findName(data)

Performs find name on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
data any required Passed through to the implementation as written.

util.cleanContent

Signature

discord.util.cleanContent(text, context)

Performs clean content on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
text any required Passed through to the implementation as written.
context any required Passed through to the implementation as written.

util.cleanCodeBlockContent

Signature

discord.util.cleanCodeBlockContent(text)

Performs clean code block content on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
text any required Passed through to the implementation as written.

util.parseWebhookURL

Signature

discord.util.parseWebhookURL(url)

Performs parse webhook url on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
url any required Passed through to the implementation as written.

util.transformResolved

Signature

discord.util.transformResolved(resolved)

Performs transform resolved on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
resolved any required Passed through to the implementation as written.

util.resolveSKUId

Signature

discord.util.resolveSKUId(sku)

Performs resolve skuid on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
sku any required Passed through to the implementation as written.

util.with_wrapped

Signature

discord.util.with_wrapped(client, wrap_fn, callback)

Performs with wrapped on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
client any required Passed through to the implementation as written.
wrap_fn any required Passed through to the implementation as written.
callback function optional Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error.

util.join_args

Signature

discord.util.join_args(args, startIndex, fallback)

Performs join args on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
args any required Passed through to the implementation as written.
startIndex any required Passed through to the implementation as written.
fallback any required Passed through to the implementation as written.

util.permission_name

Signature

discord.util.permission_name(bit)

Performs permission name on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
bit any required Passed through to the implementation as written.

util.public_error

Signature

discord.util.public_error(err)

Performs public error on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
err any required Passed through to the implementation as written.

util.request

Signature

discord.util.request(client, method, path, body, callback)

Performs request on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
client any required Passed through to the implementation as written.
method any required Passed through to the implementation as written.
path any required Passed through to the implementation as written.
body any required Passed through to the implementation as written.
callback function optional Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error.

util.message_ids_from_json

Signature

discord.util.message_ids_from_json(body)

Performs message ids from json on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
body any required Passed through to the implementation as written.

util.count

Signature

discord.util.count(value)

Performs count on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.parse_duration_ms

Signature

discord.util.parse_duration_ms(value)

Performs parse duration ms on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
value any required Passed through to the implementation as written.

util.timeout_until

Signature

discord.util.timeout_until(duration)

Performs timeout until on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
duration any required Passed through to the implementation as written.
Search Ctrl K Navigate Open Esc