Beispiel #1
0
        public async Task Start()
        {
            // create the placeholder command service and init module.
            var _commands = new CommandService();
            var init      = new Initialize(commands: _commands);

            // Setup the socket config.
            var botConfig = new DiscordSocketConfig
            {
                GuildSubscriptions = false,
                TotalShards        = 1,
                LogLevel           = LogLevel,
                RateLimitPrecision = RateLimitPrecision.Millisecond,
                UseSystemClock     = false
            };

            // Log the client in for the first time and get the Discord recommnded
            // shard count.

            Client = init.BuildInitalBoot().GetRequiredService <DiscordShardedClient>();

            await Client.LoginAsync(TokenType.Bot, Resources.Token).ConfigureAwait(false);

            botConfig.TotalShards = await Client.GetRecommendedShardCountAsync().ConfigureAwait(false);

            await Client.LogoutAsync().ConfigureAwait(false);

            // Recreate the init as to use the new shard config and initalize the services.

            init = new Initialize(_commands, new DiscordShardedClient(botConfig));

            var services = init.BuildServiceProvider();

            Client = services.GetRequiredService <DiscordShardedClient>();

            await services.GetRequiredService <CommandHandlingService>().InitalizeAsync();

            services.GetRequiredService <LoggingService>().Initalize();

            services.GetRequiredService <GuildTransferService>().Initalize();

            // Start the client.

            await Client.LoginAsync(TokenType.Bot, Resources.Token).ConfigureAwait(false);

            await Client.StartAsync();
        }
Beispiel #2
0
        public async Task MainAsync()
        {
            // First init, check config incase its missing.
            Initialize.Start();

            using (var services = ConfigureServices())
            {
                var loader = new ConfigurationLoader();
                _config = loader.LoadConfig <Configuration>();

                var client = services.GetRequiredService <DiscordSocketClient>();

                client.Log += LogAsync;
                services.GetRequiredService <CommandService>().Log += LogAsync;

                await client.LoginAsync(TokenType.Bot, _config.Token);

                await client.StartAsync();

                await services.GetRequiredService <CommandHandlingService>().InitializeAsync();

                await Task.Delay(Timeout.Infinite);
            }
        }