示例#1
0
        public async Task RunBotAsync()
        {
            string botToken    = Config.BotToken;
            var    _HttpClient = new HttpClient();

            _client            = new DiscordSocketClient();
            _commands          = new CommandService();
            _botInitialization = new BotInitialization(_client);


            _services = new ServiceCollection()
                        .AddSingleton(_commands)
                        .BuildServiceProvider();

            _client.UserJoined += UserJoined.UserJoinedServer;
            _client.Ready      += BotInitialization.StartUpMessages;

            _client.Log += Log;

            await RegisterCommandAsync();

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

            await _client.StartAsync();

            await Task.Delay(-1);
        }
示例#2
0
 public BotService(
     IRepository <Bot> repository,
     IRepository <Message> messageService)
     : base(repository)
 {
     _botInit        = new BotInitialization();
     _messageService = messageService;
 }
示例#3
0
        public async Task RunBotAsync()
        {
            try
            {
                await InitializeConfig();

                var _HttpClient = new HttpClient();

                DiscordSocketConfig botConfig = new DiscordSocketConfig()
                {
                  MessageCacheSize = 5000,
                  AlwaysDownloadUsers = true,
                 
                };


                _client = new DiscordSocketClient(botConfig);

                CommandServiceConfig CommandServiceConfig = new CommandServiceConfig()
                {
                    DefaultRunMode = RunMode.Async

                };
                _commands = new CommandService(CommandServiceConfig);

                _botInitialization = new BotInitialization(_client);
                _onMessage = new OnMessage(_client);

                _services = new ServiceCollection()
                     .AddSingleton(_commands)
                     .AddSingleton(_client)
                     .BuildServiceProvider();

                _client.MessageUpdated += _onMessage.UpdatedMessageContainsAsync;
                _client.Ready += BotInitialization.GIRUBotInitializationTasks;

                _client.Log += Log;

                await RegisterCommandAsync();
                await _client.LoginAsync(TokenType.Bot, Global.Config.BotToken);
                await _client.StartAsync();


                await Task.Delay(-1);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error running bot..\n------- EXCEPTION -------\n {ex.Message}\n------- \\EXCEPTION -------");
            }
        }