DiscordLua
discorddiscord
v1.2.4
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.4 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.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.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: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: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: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.

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:setToken(os.getenv("DISCORD_TOKEN"))

Static members

  • REST.cdn

Examples

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

ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationRoleConnectionMetadata · Attachment

Version: discord 1.2.4 · runtime 1.0.0

Search Ctrl K Navigate Open Esc