DiscordLua
discorddiscord
v1.2.9
Install

REST

Class
On this page

REST is a DiscordLua class representing a Discord resource. Obtain it from a manager, an event payload, or the constructor when one is documented below.

class Module 1.2.9 Source

Constructor

REST.new(client, options)

The class table is callable, so REST(client, options) is the same as .new.

NameTypeRequiredBehavior
client 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.
lua
local discord = require("discord")
local object = discord.REST({}, {})

Properties

REST.agent

# mutable
Name
agent
Type
any
Access
mutable
Description
Instance field REST.agent. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.cdn

# readonly
Name
cdn
Type
CDN
Access
readonly
Description
Instance field REST.cdn. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.
Related
CDN

REST.client

# readonly
Name
client
Type
any
Access
readonly
Description
Owning Client instance used for REST, cache, and event dispatch.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.globalDelay

# readonly
Name
globalDelay
Type
any
Access
readonly
Description
Instance field REST.globalDelay. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.globalRemaining

# readonly
Name
globalRemaining
Type
any
Access
readonly
Description
Instance field REST.globalRemaining. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.globalReset

# readonly
Name
globalReset
Type
any
Access
readonly
Description
Instance field REST.globalReset. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.handlers

# readonly
Name
handlers
Type
Collection
Access
readonly
Description
Instance field REST.handlers. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.
Related
Collection

REST.hashes

# readonly
Name
hashes
Type
Collection
Access
readonly
Description
Instance field REST.hashes. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.
Related
Collection

REST.options

# readonly
Name
options
Type
any
Access
readonly
Description
Instance field REST.options. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

REST.token

# mutable
Name
token
Type
any
Access
mutable
Description
Authentication token held by this REST. Do not log this value.
Availability
Set by login. Do not log this value.

REST.version

# readonly
Name
version
Type
any
Access
readonly
Description
Instance field REST.version. Read it after the object is constructed or wrapped from Gateway/REST data.
Availability
Populated from the Gateway/REST payload or constructor for this REST.

Methods

REST:clearHandlerSweeper()

#

Performs clear handler sweeper on this REST. Call it from bot code when you need that operation on the current object.

Signature

REST:clearHandlerSweeper()

Parameters

No parameters.

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:clearHandlerSweeper()

REST:clearHashSweeper()

#

Performs clear hash sweeper on this REST. Call it from bot code when you need that operation on the current object.

Signature

REST:clearHashSweeper()

Parameters

No parameters.

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:clearHashSweeper()

REST:delete()

#

Permanently delete this resource through REST.

Signature

REST:delete(path, options, callback)

Parameters

NameTypeRequiredBehavior
path 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.
callback function optional Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error.

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:delete(path, {}, function(err, result)
    if err then error(err) end
end)

REST:get()

#

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

Signature

REST:get(path, options, callback)

Parameters

NameTypeRequiredBehavior
path 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.
callback function optional Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error.

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:get(path, {}, function(err, result)
    if err then error(err) end
end)

REST:patch()

#

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

Signature

REST:patch(path, body, callback)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:patch(path, body, function(err, result)
    if err then error(err) end
end)

REST:post()

#

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

Signature

REST:post(path, body, callback)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:post(path, body, function(err, result)
    if err then error(err) end
end)

REST:put()

#

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

Signature

REST:put(path, body, callback)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:put(path, body, function(err, result)
    if err then error(err) end
end)

REST:queueRequest()

#

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

Signature

REST:queueRequest(request)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:queueRequest(request)

REST:request()

#

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

Signature

REST:request(method, path, bodyOrOptions, callback)

Parameters

NameTypeRequiredBehavior
method any required Passed through to the implementation as written.
path any required Passed through to the implementation as written.
bodyOrOptions table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.
callback function optional Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error.

Returns

REST — the same instance, for chaining.

Throws

A DiscordLua error when arguments are invalid or the request fails without a callback.

Example

lua
local discord = require("discord")
-- object is a REST
object:request(method, path, {}, function(err, result)
    if err then error(err) end
end)

REST:setAgent()

#

Set the Agent field. Builders return this REST so setters can be chained.

Signature

REST:setAgent(agent)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:setAgent(agent)

REST:setToken()

#

Set the Token field. Builders return this REST so setters can be chained.

Signature

REST:setToken(token)

Parameters

NameTypeRequiredBehavior
token string optional Bot token. When omitted, Client:login reads DISCORD_TOKEN.

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:setToken(os.getenv("DISCORD_TOKEN"))

REST:updateRateLimit()

#

Performs update rate limit on this REST. Call it from bot code when you need that operation on the current object.

Signature

REST:updateRateLimit(method, path, info)

Parameters

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

Returns

REST — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a REST
object:updateRateLimit(method, path, info)

Static members

  • REST.cdn
  • REST.getUserAgentAppendix
  • REST.majorParameter
  • REST.parseResponse
  • REST.routeHash
  • REST.shouldUseGlobalFetchAndWebSocket

Examples

lua
local discord = require("discord")
local object = discord.REST({})

ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationCommandNumericOptionMinMaxValueMixin · ApplicationCommandOptionBase

Version: discord 1.2.9 · runtime 1.0.0

Search Ctrl K Navigate Open Esc