DiscordLua
discorddiscord
v1.2.4
Install

cls

Class
On 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.

class Module 1.2.4 Source

Constructor

cls.new(message, extra)

The class table is callable, so cls(message, extra) is the same as .new.

NameTypeRequiredBehavior
message any required Passed through to the implementation as written.
extra any optional Passed through to the implementation as written.
lua
local discord = require("discord")
local object = discord.cls({}, {})

Properties

cls.code

# readonly
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.

cls.data

# readonly
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.

cls.extra

# readonly
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.

cls.message

# readonly
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.

cls.method

# readonly
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.

cls.name

# readonly
Name
name
Type
any
Access
readonly
Description
Display name of this cls.
Availability
Populated from the Gateway/REST payload or constructor for this cls.

cls.path

# readonly
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.

cls.retryAfter

# readonly
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.

cls.status

# readonly
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

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

Returns

cls — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a cls
object:addOptions(...)

cls.from()

# static

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

Signature

cls.from(data)

Parameters

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

Returns

any.

Example

lua
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

NameTypeRequiredBehavior
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

lua
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

NameTypeRequiredBehavior
id string required Snowflake id string.

Returns

cls — the same instance, for chaining.

Example

lua
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

NameTypeRequiredBehavior
isDefault any optional Passed through to the implementation as written.

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

NameTypeRequiredBehavior
id string required Snowflake id string.

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

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

Returns

cls — the same instance, for chaining.

Example

lua
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

lua
local discord = require("discord")
-- object is a cls
object:toJSON()

Examples

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

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

Version: discord 1.2.4 · runtime 1.0.0

Search Ctrl K Navigate Open Esc