private async Task MainAsync2() { _client = new DiscordSocketClient(); _client.Log += Log; string token = BotConfig.Token; // Remember to keep this private! await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); TextConsole.Log($"_client.Latency: {_client.Latency}"); // Block this task until the program is closed. await Task.Delay(-1); }
public async void Start(CancellationToken ct) { try { // ***Send a token to carry the message if cancellation is requested. TextConsole.Log("Discord Bot starting..."); // await MainAsync(cts.Token); TextConsole.Log("Discord Bot"); } // *** If cancellation is requested, an OperationCanceledException results. catch (OperationCanceledException) { TextConsole.Log("Discord Bot stopped!"); } catch (Exception e) { TextConsole.Log("Exception: " + e.Message); } }
public static void SetToken(string token) { //TODO: change token is possible only if bot not working _token = token; TextConsole.Log("Token has been successfully set."); }
private Task Log(LogMessage msg) { TextConsole.Log(msg.ToString()); return(Task.CompletedTask); }