DiscordLua
discorddiscord
v1.2.4
Install

ShardingManager

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

manager Module 1.2.4 REST Source

Constructor

ShardingManager.new(file, options)

The class table is callable, so ShardingManager(file, options) is the same as .new.

NameTypeRequiredBehavior
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.
lua
local discord = require("discord")
local object = discord.ShardingManager({}, {})

Properties

ShardingManager.env

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

ShardingManager.execArgv

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

ShardingManager.file

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

ShardingManager.mode

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

ShardingManager.respawn

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

ShardingManager.respawnDelay

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

ShardingManager.shardArgs

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

ShardingManager.shardList

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

ShardingManager.shards

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

ShardingManager.silent

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

ShardingManager.spawnFn

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

ShardingManager.timeout

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

ShardingManager.token

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

ShardingManager.totalShards

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

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

Returns

ShardingManager — the same instance, for chaining.

Example

lua
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

NameTypeRequiredBehavior
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

ValidationError

Example

lua
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

NameTypeRequiredBehavior
id string required Snowflake id string.

Returns

ShardingManager — the same instance, for chaining.

Example

lua
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

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

ShardingManager — the same instance, for chaining.

Example

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

ShardingManager.fetchRecommendedShardCount()

# static

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

Signature

ShardingManager.fetchRecommendedShardCount(token, options, callback)

Parameters

NameTypeRequiredBehavior
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

lua
local discord = require("discord")
-- object is a ShardingManager
ShardingManager.fetchRecommendedShardCount(os.getenv("DISCORD_TOKEN"), {}, function(err, result)
    if err then error(err) end
end)

ShardingManager.fetchRecommendedShards()

# static REST

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

Signature

ShardingManager.fetchRecommendedShards(token, callback)

Parameters

NameTypeRequiredBehavior
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

AuthenticationError

Side effects

Sends an HTTP request through the native REST client. Rate-limit headers are honored by the runtime.

Example

lua
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

lua
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

AuthenticationError

Example

lua
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

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

ShardingManager — the same instance, for chaining.

Example

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

ShardingManager.resolveShardOptions()

# static

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

NameTypeRequiredBehavior
options table optional Lua option table. Field names match the corresponding DiscordLua option type when one exists.

Returns

any.

Example

lua
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

NameTypeRequiredBehavior
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

lua
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

NameTypeRequiredBehavior
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

lua
local discord = require("discord")
-- object is a ShardingManager
object:spawn(amount, delay, function(err, result)
    if err then error(err) end
end)

Examples

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

ApplicationCommandManager · ApplicationCommandPermissionsManager · ApplicationEmojiManager · AutoModerationRuleManager · BaseGuildEmojiManager · BaseManager · CachedManager · CategoryChannelChildManager

Version: discord 1.2.4 · runtime 1.0.0

Search Ctrl K Navigate Open Esc