示例#1
0
        public async Task RunBotAsync()
        {
            if (string.IsNullOrEmpty(Config.Bot.Token))
            {
                return;
            }
            _client = new DiscordShardedClient(_shardIds, new DiscordSocketConfig
            {
                LogLevel         = LogSeverity.Verbose,
                DefaultRetryMode = RetryMode.AlwaysRetry,
                MessageCacheSize = 50,
                TotalShards      = 2
            });

            _services = ConfigureServices();
            _services.GetRequiredService <DiscordEventHandler>().InitDiscordEvents();
            await _services.GetRequiredService <CommandHandeling>().InitializeAsync();

            var botToken = Config.Bot.Token;
            await _client.SetGameAsync("Boole! | *help");

            await _client.LoginAsync(TokenType.Bot, botToken);

            await _client.StartAsync();


            SendMessagesUsingConsole.ConsoleInput(_client);
            await Task.Delay(-1);
        }
示例#2
0
        public async Task RunBotAsync()
        {
            _client = new DiscordShardedClient(_shardIds, new DiscordSocketConfig
            {
                LogLevel         = LogSeverity.Verbose,
                DefaultRetryMode = RetryMode.AlwaysRetry,
                MessageCacheSize = 50,
                TotalShards      = 2
            });

            _services = new Container(x =>
            {
                x.AddSingleton(_client)
                .AddSingleton <CancellationTokenSource>()
                .AddSingleton <CommandService>()
                .AddSingleton <HttpClient>()
                .AddSingleton <IDataStorage, JsonLocalStorage>()
                .AddSingleton <ILocalization, JsonLocalization>()
                .AutoAddSingleton()
                .AutoAddTransient()
                .BuildServiceProvider();
            });

            await _services.InitializeServicesAsync();

            await _client.SetGameAsync("Boole~");

            await _client.LoginAsync(TokenType.Bot, _services.GetRequiredService <Config>().Token);

            await _client.StartAsync();

            SendMessagesUsingConsole.ConsoleInput(_client);

            try
            {
                await Task.Delay(-1, _services.GetRequiredService <CancellationTokenSource>().Token);
            }
            catch (TaskCanceledException)
            { }
        }