示例#1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Starting discord bot");

            if (_config.GetValue("bot:DISCORD_TOKEN", string.Empty) == string.Empty)
            {
                _logger.LogWarning("Missing configuration entry bot:DISCORD_TOKEN");
                return;
            }

            _client = new DiscordSocketClient();

            _client.Log += (LogMessage msg) =>
            {
                _logger.LogInformation(msg.ToString());
                return(Task.CompletedTask);
            };

            _client.MessageReceived += MessageReceived;

            _discordHelper = new DiscordHelper(_config["DATACORE_WEB"], _logger, _searcher.Searcher, _searcher.VoyImage, _crewData.BotHelper);

            await _client.LoginAsync(TokenType.Bot, _config["bot:DISCORD_TOKEN"]);

            await _client.StartAsync();

            await _client.SetActivityAsync(new Game("with Spot", ActivityType.Playing));
        }
示例#2
0
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Stopping discord bot");

            if (_client != null)
            {
                _client.MessageReceived -= MessageReceived;
                await _client.LogoutAsync();

                await _client.StopAsync();

                _client        = null;
                _discordHelper = null;
            }
        }