ShardingManager
ManagerOn this page
ShardingManager is the cache and REST facade for Sharding objects owned by the parent. Typical calls are fetch, create, edit, delete, resolve, and resolveId.
Constructor
ShardingManager.new(file, options) The class table is callable, so ShardingManager(file, options) is the same as .new.
| Name | Type | Required | Behavior |
|---|---|---|---|
file |
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.ShardingManager({}, {})Properties
- Name
env- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.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 ShardingManager.
- Name
execArgv- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.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 ShardingManager.
- Name
file- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.file. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
mode- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.mode. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
respawn- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.respawn. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
respawnDelay- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.respawnDelay. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
shardArgs- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.shardArgs. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
shardList- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.shardList. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
shards- Type
- Collection
- Access
- readonly
- Description
- Instance field
ShardingManager.shards. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Related
- Collection
- Name
silent- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.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 ShardingManager.
- Name
spawnFn- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.spawnFn. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
timeout- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.timeout. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
- Name
token- Type
any- Access
- readonly
- Description
- Authentication token held by this ShardingManager. Do not log this value.
- Availability
- Set by
login. Do not log this value.
- Name
totalShards- Type
any- Access
- readonly
- Description
- Instance field
ShardingManager.totalShards. Read it after the object is constructed or wrapped from Gateway/REST data. - Availability
- Populated from the Gateway/REST payload or constructor for this ShardingManager.
Methods
ShardingManager:broadcast()
#Performs broadcast on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager:broadcast(message) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
message |
any |
required | Passed through to the implementation as written. |
Returns
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:broadcast(message)ShardingManager:broadcastEval()
#Evaluate a Lua source string on every shard and collect results.
Signature
ShardingManager:broadcastEval(script, options, callback) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
script |
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
ShardingManager — the same instance, for chaining.
Throws
Example
local discord = require("discord")
-- object is a ShardingManager
object:broadcastEval(script, {}, function(err, result)
if err then error(err) end
end)ShardingManager:createShard()
#Create Shard through REST and cache the result when the request succeeds. Pass function(err, result) to handle failures without raising.
Signature
ShardingManager:createShard(id) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
id |
string |
required | Snowflake id string. |
Returns
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:createShard("123")ShardingManager:fetchClientValues()
#Read a property path from every shard client.
Signature
ShardingManager:fetchClientValues(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
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:fetchClientValues(prop, function(err, result)
if err then error(err) end
end)Fetch RecommendedShardCount from REST and update the local cache when the request succeeds.
Signature
ShardingManager.fetchRecommendedShardCount(token, options, callback) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
token |
string |
optional | Bot token. When omitted, Client:login reads DISCORD_TOKEN. |
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
any.
Example
local discord = require("discord")
-- object is a ShardingManager
ShardingManager.fetchRecommendedShardCount(os.getenv("DISCORD_TOKEN"), {}, function(err, result)
if err then error(err) end
end)Fetch RecommendedShards from REST and update the local cache when the request succeeds.
Signature
ShardingManager.fetchRecommendedShards(token, callback) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
token |
string |
optional | Bot token. When omitted, Client:login reads DISCORD_TOKEN. |
callback |
function |
optional | Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error. |
Returns
any. REST helpers may return the wrapped resource, or invoke callback(err, result) instead of returning it.
Throws
Side effects
Sends an HTTP request through the native REST client. Rate-limit headers are honored by the runtime.
Example
local discord = require("discord")
-- object is a ShardingManager
ShardingManager.fetchRecommendedShards(os.getenv("DISCORD_TOKEN"), function(err, result)
if err then error(err) end
end)ShardingManager:ids()
#Performs ids on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager:ids() Parameters
No parameters.
Returns
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:ids()ShardingManager:kill()
#Performs kill on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager:kill() Parameters
No parameters.
Returns
ShardingManager — the same instance, for chaining.
Throws
Example
local discord = require("discord")
-- object is a ShardingManager
object:kill()ShardingManager:on()
#Performs on on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager: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
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:on(event, function(err, result)
if err then error(err) end
end)Performs resolve shard options on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager.resolveShardOptions(options) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
options |
table |
optional | Lua option table. Field names match the corresponding DiscordLua option type when one exists. |
Returns
any.
Example
local discord = require("discord")
-- object is a ShardingManager
ShardingManager.resolveShardOptions({})ShardingManager:respawnAll()
#Performs respawn all on this ShardingManager. Call it from bot code when you need that operation on the current object.
Signature
ShardingManager:respawnAll(shardDelay, respawnDelay, timeout) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
shardDelay |
number |
required | Duration in milliseconds. |
respawnDelay |
number |
required | Duration in milliseconds. |
timeout |
number |
required | Duration in milliseconds. |
Returns
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:respawnAll(shardDelay, respawnDelay, timeout)ShardingManager:spawn()
#Start child processes or shards.
Signature
ShardingManager:spawn(amount, delay, callback) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
amount |
any |
required | Passed through to the implementation as written. |
delay |
number |
required | Duration in milliseconds. |
callback |
function |
optional | Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error. |
Returns
ShardingManager — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a ShardingManager
object:spawn(amount, delay, function(err, result)
if err then error(err) end
end)Examples
local discord = require("discord")
local object = discord.ShardingManager({})Related APIs
ApplicationCommandManager · ApplicationCommandPermissionsManager · ApplicationEmojiManager · AutoModerationRuleManager · BaseGuildEmojiManager · BaseManager · CachedManager · CategoryChannelChildManager
Version: discord 1.2.4 · runtime 1.0.0