Shard
ClassOn 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.
Constructor
Shard.new(manager, id) The class table is callable, so Shard(manager, id) is the same as .new.
| Name | Type | Required | Behavior |
|---|---|---|---|
manager |
any |
required | Passed through to the implementation as written. |
id |
string |
required | Snowflake id string. |
local discord = require("discord")
local object = discord.Shard({}, {})Properties
- 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.
- 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.
- 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.
- Name
id- Type
any- Access
- readonly
- Description
- Snowflake id of this Shard.
- Availability
- Populated from the Gateway/REST payload or constructor for this Shard.
- 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.
- 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.
- 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.
- 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.
- 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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
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
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
| Name | Type | Required | Behavior |
|---|---|---|---|
delay |
number |
required | Duration in milliseconds. |
Returns
Shard — the same instance, for chaining.
Example
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
| Name | Type | Required | Behavior |
|---|---|---|---|
message |
any |
required | Passed through to the implementation as written. |
Returns
Shard — the same instance, for chaining.
Example
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
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).
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).
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).
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).
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).
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).
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).
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).
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).
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).
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).
object:on("spawn", function(...)
-- handler arguments match the DiscordLua emit for this event
end)Examples
local discord = require("discord")
local object = discord.Shard({})Related APIs
ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationRoleConnectionMetadata · Attachment
Version: discord 1.2.4 · runtime 1.0.0