DiscordShardManager

open class DiscordShardManager : DiscordShardDelegate, Lockable

The shard manager is responsible for a client’s shards. It decides when a client is considered connected. Connected being when all shards have recieved a ready event and are receiving events from the gateway. It also decides when a client has fully disconnected. Disconnected being when all shards have closed.

  • Connects all shards to the gateway.

    Note This method is an async method.

    Declaration

    Swift

    open func connect()
  • Creates a new shard.

    Declaration

    Swift

    open func createShardWithDelegate(_ delegate: DiscordShardManagerDelegate, withShardNum shardNum: Int,
                                      totalShards: Int) -> DiscordShard

    Parameters

    delegate

    The delegate for this shard.

    withShardNum

    The shard number for the new shard.

    totalShards

    The total number of shards.

    Return Value

    A new DiscordShard

  • Disconnects all shards.

    Declaration

    Swift

    open func disconnect()
  • Use when you will have multiple shards spread across a few instances.

    Declaration

    Swift

    open func manuallyShatter(withInfo info: DiscordShardInformation)

    Parameters

    withInfo

    The information about this single shard.

  • Sends a payload on the specified shard.

    Declaration

    Swift

    open func sendPayload(_ payload: DiscordGatewayPayload, onShard shard: Int)

    Parameters

    payload

    The payload to send.

    onShard

    The shard to send the payload on.

  • Handles engine dispatch events. You shouldn’t need to call this method directly.

    Override to provide custom engine dispatch functionality.

    Declaration

    Swift

    open func shard(_ shard: DiscordShard, didReceiveEvent event: DiscordDispatchEvent,
                    with payload: DiscordGatewayPayload)

    Parameters

    shard

    The engine that received the event.

    didReceiveEvent

    The event that was received.

    payload

    A DiscordGatewayPayload containing the dispatch information.

  • Called when an engine handled a hello packet.

    • gotHelloWithPayload: The hello data.

    Declaration

    Swift

    open func shard(_ engine: DiscordShard, gotHelloWithPayload payload: DiscordGatewayPayload)

    Parameters

    shard

    The shard that received the event.

  • Used by shards to signal that they have connected.

    Declaration

    Swift

    open func shardDidConnect(_ shard: DiscordShard)

    Parameters

    shardNum

    The number of the shard that disconnected.

  • Used by shards to signal that they have disconnected

    Declaration

    Swift

    open func shardDidDisconnect(_ shard: DiscordShard)

    Parameters

    shardNum

    The number of the shard that disconnected.