connectGatewayWithOptions static method

Future<NyxxGateway> connectGatewayWithOptions(
  1. GatewayApiOptions apiOptions,
  2. [GatewayClientOptions clientOptions = const GatewayClientOptions()]
)

Create an instance of NyxxGateway using the provided options.

Implementation

static Future<NyxxGateway> connectGatewayWithOptions(
  GatewayApiOptions apiOptions, [
  GatewayClientOptions clientOptions = const GatewayClientOptions(),
]) async {
  clientOptions.logger
    ..info('Connecting to the Gateway API')
    ..fine(
      'Token: ${apiOptions.token}, Authorization: ${apiOptions.authorizationHeader}, User-Agent: ${apiOptions.userAgent},'
      ' Intents: ${apiOptions.intents.value}, Payloads: ${apiOptions.payloadFormat.value}, Compression: ${apiOptions.compression.name},'
      ' Shards: ${apiOptions.shards?.join(', ')}, Total shards: ${apiOptions.totalShards}, Large threshold: ${apiOptions.largeThreshold}',
    )
    ..fine('Plugins: ${clientOptions.plugins.map((plugin) => plugin.name).join(', ')}');

  return _doConnect(apiOptions, clientOptions, () async {
    final client = NyxxGateway._(apiOptions, clientOptions);

    client
      .._application = await client.applications.fetchCurrentApplication()
      .._user = await client.users.fetchCurrentUser();

    // We can't use client.gateway as it is not initialized yet
    final gatewayManager = GatewayManager(client);

    final gatewayBot = await gatewayManager.fetchGatewayBot();
    return client..gateway = await Gateway.connect(client, gatewayBot);
  }, clientOptions.plugins);
}