init method

Future<void> init()

Implementation

Future<void> init () async {
  await environment.load();

  Http http = Http(baseUrl: 'https://discord.com/api');
  http.defineHeader(header: 'Content-Type', value: 'application/json');
  ioc.bind(namespace: Service.http, service: http);

  String? report = environment.get('REPORTER');
  if (report != null) {
    ReporterManager reporter = ReporterManager(Directory(join(Directory.current.path, 'logs')));
    reporter.reportLevel = report;

    ioc.bind(namespace: Service.reporter, service: reporter);
  }

  String? token = environment.get('APP_TOKEN');
  if (token == null) {
    throw TokenException(
      prefix: 'MISSING TOKEN',
      cause: 'APP_TOKEN is not defined in your environment'
    );
  }

  await modules.load(this);
  await plugins.load();

  final String? shardsCount = environment.get('SHARDS_COUNT');

  ShardManager manager = ShardManager(http, token, intents.list);
  manager.start(shardsCount: (shardsCount != null ? int.tryParse(shardsCount) : null));

  ioc.bind(namespace: Service.shards, service: manager);
}