REST
ClassOn 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.
Constructor
REST.new(client, options) The class table is callable, so REST(client, options) is the same as .new.
| Name | Type | Required | Behavior |
|---|---|---|---|
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. |
local discord = require("discord")
local object = discord.REST({}, {})Properties
- 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.
- 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.
- 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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
local discord = require("discord")
-- object is a REST
object:setToken(os.getenv("DISCORD_TOKEN"))Static members
-
REST.cdn
Examples
local discord = require("discord")
local object = discord.REST({})Related APIs
ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationRoleConnectionMetadata · Attachment
Version: discord 1.2.4 · runtime 1.0.0