DiscordLua
discorddiscord
v1.2.4
Install

Shard

Class
On this page

Shard 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

Shard.new(manager, id)

The class table is callable, so Shard(manager, id) is the same as .new.

NameTypeRequiredBehavior
manager any required Passed through to the implementation as written.
id string required Snowflake id string.
lua
local discord = require("discord")
local object = discord.Shard({}, {})

Properties

Shard.args

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

Shard.env

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

Shard.execArgv

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

Shard.id

# readonly
Name
id
Type
any
Access
readonly
Description
Snowflake id of this Shard.
Availability
Populated from the Gateway/REST payload or constructor for this Shard.

Shard.manager

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

Shard.process

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

Shard.ready

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

Shard.silent

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

Shard.worker

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

Methods

Shard:eval()

#

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

Signature

Shard:eval(script, callback)

Parameters

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

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:eval(script, function(err, result)
    if err then error(err) end
end)

Shard:fetchClientValue()

#

Fetch ClientValue from REST and update the local cache when the request succeeds.

Signature

Shard:fetchClientValue(prop, callback)

Parameters

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

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:fetchClientValue(prop, function(err, result)
    if err then error(err) end
end)

Shard:kill()

#

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

Signature

Shard:kill()

Parameters

No parameters.

Returns

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:kill()

Shard:on()

#

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

Signature

Shard:on(event, callback)

Parameters

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

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:on(event, function(err, result)
    if err then error(err) end
end)

Shard:respawn()

#

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

Signature

Shard:respawn(delay)

Parameters

NameTypeRequiredBehavior
delay number required Duration in milliseconds.

Returns

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:respawn(delay)

Shard:send()

#

Send a message, payload, or packet using this object.

Signature

Shard:send(message)

Parameters

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

Returns

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:send(message)

Shard:spawn()

#

Start child processes or shards.

Signature

Shard:spawn()

Parameters

No parameters.

Returns

Shard — the same instance, for chaining.

Example

lua
local discord = require("discord")
-- object is a Shard
object:spawn()

Events

death

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("death", handler).

lua
object:on("death", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

disconnect

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("disconnect", handler).

lua
object:on("disconnect", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

message

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("message", handler).

lua
object:on("message", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

reconnecting

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("reconnecting", handler).

lua
object:on("reconnecting", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

resume

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("resume", handler).

lua
object:on("resume", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

shardCreate

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("shardCreate", handler).

lua
object:on("shardCreate", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

shardDisconnect

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("shardDisconnect", handler).

lua
object:on("shardDisconnect", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

shardError

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("shardError", handler).

lua
object:on("shardError", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

shardReady

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("shardReady", handler).

lua
object:on("shardReady", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

shardReconnecting

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("shardReconnecting", handler).

lua
object:on("shardReconnecting", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

spawn

#

Emitted by Shard when the corresponding Gateway or local lifecycle update occurs. Listen with :on("spawn", handler).

lua
object:on("spawn", function(...)
    -- handler arguments match the DiscordLua emit for this event
end)

Examples

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

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

Version: discord 1.2.4 · runtime 1.0.0

Search Ctrl K Navigate Open Esc