diff --git a/TeleBot/TeleBot/TelegramBotService.cs b/TeleBot/TeleBot/TelegramBotService.cs index 9363a36..482ea36 100644 --- a/TeleBot/TeleBot/TelegramBotService.cs +++ b/TeleBot/TeleBot/TelegramBotService.cs @@ -229,12 +229,16 @@ namespace TeleBot public async Task UpdateBotTokenAsync(string newToken) { - if (_botClient != null && _currentBotToken != newToken) + // If bot wasn't started or token changed, start/restart + if (_currentBotToken != newToken || _botClient == null) { - _logger.LogInformation("Updating bot token and restarting bot..."); + _logger.LogInformation("Starting/updating bot with new token..."); - // Stop current bot - _cancellationTokenSource?.Cancel(); + // Stop current bot if running + if (_botClient != null) + { + _cancellationTokenSource?.Cancel(); + } // Create new bot client with new token and TOR support _currentBotToken = newToken;