cls
ClassOn this page
cls 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
cls.new(message, extra) The class table is callable, so cls(message, extra) is the same as .new.
| Name | Type | Required | Behavior |
|---|---|---|---|
message |
any |
required | Passed through to the implementation as written. |
extra |
any |
optional | Passed through to the implementation as written. |
local discord = require("discord")
local object = discord.cls({}, {})Properties
- Name
code- Type
any- Access
- readonly
- Description
- Instance field
cls.code. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
data- Type
any- Access
- readonly
- Description
- Instance field
cls.data. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
extra- Type
any- Access
- readonly
- Description
- Instance field
cls.extra. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
message- Type
any- Access
- readonly
- Description
- Instance field
cls.message. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
method- Type
any- Access
- readonly
- Description
- Instance field
cls.method. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
name- Type
any- Access
- readonly
- Description
- Display name of this cls.
- Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
path- Type
any- Access
- readonly
- Description
- Instance field
cls.path. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
retryAfter- Type
any- Access
- readonly
- Description
- Instance field
cls.retryAfter. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
- Name
status- Type
any- Access
- readonly
- Description
- Instance field
cls.status. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this cls.
Methods
cls:addOptions()
#Add Options to this cls.
Signature
cls:addOptions(...) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
... |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:addOptions(...)Performs from on this cls. Call it from bot code when you need that operation on the current object.
Signature
cls.from(data) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
data |
any |
required | Passed through to the implementation as written. |
Returns
any.
Example
local discord = require("discord")
-- object is a cls
cls.from(data)cls:raise()
#Performs raise on this cls. Call it from bot code when you need that operation on the current object.
Signature
cls:raise(level) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
level |
any |
required | Passed through to the implementation as written. |
Returns
any.
Throws
A DiscordLua error when arguments are invalid or the request fails without a callback.
Example
local discord = require("discord")
-- object is a cls
object:raise(level)cls:setCustomId()
#Set the CustomId field. Builders return this cls so setters can be chained.
Signature
cls:setCustomId(id) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
id |
string |
required | Snowflake id string. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setCustomId("123")cls:setDefault()
#Set the Default field. Builders return this cls so setters can be chained.
Signature
cls:setDefault(isDefault) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
isDefault |
any |
optional | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setDefault(isDefault)cls:setDescription()
#Set the Description field. Builders return this cls so setters can be chained.
Signature
cls:setDescription(description) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
description |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setDescription(description)cls:setId()
#Set the Id field. Builders return this cls so setters can be chained.
Signature
cls:setId(id) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
id |
string |
required | Snowflake id string. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setId("123")cls:setLabel()
#Set the Label field. Builders return this cls so setters can be chained.
Signature
cls:setLabel(label) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
label |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setLabel(label)cls:setMaxValues()
#Set the MaxValues field. Builders return this cls so setters can be chained.
Signature
cls:setMaxValues(value) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
value |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setMaxValues(value)cls:setMinValues()
#Set the MinValues field. Builders return this cls so setters can be chained.
Signature
cls:setMinValues(value) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
value |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setMinValues(value)cls:setOptions()
#Set the Options field. Builders return this cls so setters can be chained.
Signature
cls:setOptions(...) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
... |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setOptions(...)cls:setRequired()
#Set the Required field. Builders return this cls so setters can be chained.
Signature
cls:setRequired(required) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
required |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setRequired(required)cls:setValue()
#Set the Value field. Builders return this cls so setters can be chained.
Signature
cls:setValue(value) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
value |
any |
required | Passed through to the implementation as written. |
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:setValue(value)cls:toJSON()
#Serialize this cls into a Lua table suitable for REST or debugging.
Signature
cls:toJSON() Parameters
No parameters.
Returns
cls — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a cls
object:toJSON()Examples
local discord = require("discord")
local object = discord.cls({})Related APIs
ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationRoleConnectionMetadata · Attachment
Version: discord 1.2.4 · runtime 1.0.0