DiscordLua
discorddiscord
v1.2.9
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.linkedRoleMention

Signature

Formatters.linkedRoleMention(roleId)
NameTypeRequiredBehavior
roleId 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.email

Signature

Formatters.email(address, headers)
NameTypeRequiredBehavior
address any required Passed through to the implementation as written.
headers any required Passed through to the implementation as written.

Formatters.phoneNumber

Signature

Formatters.phoneNumber(number)
NameTypeRequiredBehavior
number any required Passed through to the implementation as written.

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.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.formatEmoji

Signature

Formatters.formatEmoji(emojiIdOrOptions, animated)
NameTypeRequiredBehavior
emojiIdOrOptions table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.
animated 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.time

Signature

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

Formatters.bold

Signature

Formatters.bold(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.italic

Signature

Formatters.italic(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.underline

Signature

Formatters.underline(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.strikethrough

Signature

Formatters.strikethrough(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.spoiler

Signature

Formatters.spoiler(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.inlineCode

Signature

Formatters.inlineCode(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.codeBlock

Signature

Formatters.codeBlock(languageOrContent, content)
NameTypeRequiredBehavior
languageOrContent string | table required Message content string, or a send/reply payload table.
content string | table required Message content string, or a send/reply payload table.

Formatters.quote

Signature

Formatters.quote(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.blockQuote

Signature

Formatters.blockQuote(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.hideLinkEmbed

Signature

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

Formatters.heading

Signature

Formatters.heading(content, level)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.
level any required Passed through to the implementation as written.

Formatters.subtext

Signature

Formatters.subtext(content)
NameTypeRequiredBehavior
content string | table required Message content string, or a send/reply payload table.

Formatters.escapeEscape

Signature

Formatters.escapeEscape(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.escapeItalic

Signature

Formatters.escapeItalic(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.escapeUnderline

Signature

Formatters.escapeUnderline(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.

Formatters.escapeSpoiler

Signature

Formatters.escapeSpoiler(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.escapeMarkdown

Signature

Formatters.escapeMarkdown(text, options)
NameTypeRequiredBehavior
text any required Passed through to the implementation as written.
options table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

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.subclass

Signature

discord.util.subclass(name, parent)

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

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

util.properties

Signature

discord.util.properties(cls, names)

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

NameTypeRequiredBehavior
cls any required Passed through to the implementation as written.
names any required Passed through to the implementation as written.

util.defineProperty

Signature

discord.util.defineProperty(cls, name, fn)

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

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

util.isMethod

Signature

discord.util.isMethod(cls, name)

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

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

util.hasProperty

Signature

discord.util.hasProperty(target, name)

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

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

util.inheritsProperties

Signature

discord.util.inheritsProperties(cls)

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

NameTypeRequiredBehavior
cls 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.decodeURIComponent

Signature

discord.util.decodeURIComponent(text)

Performs decode uricomponent 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.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.wrapCollectibles

Signature

discord.util.wrapCollectibles(data)

Performs wrap collectibles 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.wrapSharedClientTheme

Signature

discord.util.wrapSharedClientTheme(data)

Performs wrap shared client theme 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.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.

util.embedLength

Signature

discord.util.embedLength(data)

Performs embed length 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.normalizeArray

Signature

discord.util.normalizeArray(...)

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

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

util.calculateUserDefaultAvatarIndex

Signature

discord.util.calculateUserDefaultAvatarIndex(userId)

Performs calculate user default avatar index on this util. Call it from bot code when you need that operation on the current object.

NameTypeRequiredBehavior
userId string required Snowflake id string.

util.calculateShardId

Signature

discord.util.calculateShardId(guildId, shardCount)

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

NameTypeRequiredBehavior
guildId string required Snowflake id string.
shardCount any required Passed through to the implementation as written.

util.range

Signature

discord.util.range(spec)

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

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

util.lazy

Signature

discord.util.lazy(producer)

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

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

util.isJSONEncodable

Signature

discord.util.isJSONEncodable(value)

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

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

util.isEquatable

Signature

discord.util.isEquatable(value)

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

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

util.makeURLSearchParams

Signature

discord.util.makeURLSearchParams(parameters)

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

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

util.enableValidators

Signature

discord.util.enableValidators()

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

No parameters.

util.disableValidators

Signature

discord.util.disableValidators()

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

No parameters.

util.isValidationEnabled

Signature

discord.util.isValidationEnabled()

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

No parameters.

util.installBuilderValidator

Signature

discord.util.installBuilderValidator(cls, check)

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

NameTypeRequiredBehavior
cls any required Passed through to the implementation as written.
check any required Passed through to the implementation as written.

util.setPosition

Signature

discord.util.setPosition(item, position, relative, sorted, route)

Set the Position field. Builders return this util so setters can be chained.

NameTypeRequiredBehavior
item any required Passed through to the implementation as written.
position any required Passed through to the implementation as written.
relative any required Passed through to the implementation as written.
sorted any required Passed through to the implementation as written.
route any required Passed through to the implementation as written.

util.structureToJSON

Signature

discord.util.structureToJSON(self)

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

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

util.structureValueOf

Signature

discord.util.structureValueOf(self)

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

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

util.installBaseSerialisers

Signature

discord.util.installBaseSerialisers(cls)

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

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