Ejemplo n.º 1
0
        /// <summary> Connects to the Discord server with the provided email and password. </summary>
        /// <returns> Returns a token for future connections. </returns>
        public new async Task <string> Connect(string email, string password)
        {
            if (!_sentInitialLog)
            {
                SendInitialLog();
            }

            if (State != DiscordClientState.Disconnected)
            {
                await Disconnect().ConfigureAwait(false);
            }

            string token;

            try
            {
                var response = await _api.Login(email, password)
                               .Timeout(_config.APITimeout)
                               .ConfigureAwait(false);

                token = response.Token;
                if (_config.LogLevel >= LogMessageSeverity.Verbose)
                {
                    RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, "Login successful, got token.");
                }
            }
            catch (TaskCanceledException) { throw new TimeoutException(); }

            await Connect(token).ConfigureAwait(false);

            return(token);
        }