=> new Program().RunBotAsync().GetAwaiter().GetResult(); //Run program asynchronously /// <summary> /// Asynchroniczne zadanie uruchamiające bota /// </summary> /// <returns></returns> public async Task RunBotAsync() { try { //Check if bot has OAUTH2.0 token if (Config.bot.token == "" || Config.bot.token == null) { throw new ArgumentException("Invalid token"); } _client?.Dispose(); _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Verbose }); await InitializationClient(); await InitializationLogs(); //Prevent closing the program. await Task.Delay(-1); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } }
public async Task MainAsync() { Console.WriteLine("Starting GlacBot..."); client = new DiscordSocketClient(); await client.LoginAsync(TokenType.Bot, File.ReadAllText("token.txt")); await client.StartAsync(); client.MessageReceived += MessageReceived; Console.WriteLine("GlacBot started!"); Console.WriteLine("Press enter to kill the program"); Console.ReadLine(); foreach (string file in Directory.GetFiles(Environment.CurrentDirectory)) { if (file.EndsWith(".png")) { File.Delete(file); Console.WriteLine("Deleted " + file); } } await client.LogoutAsync(); client.Dispose(); }
public void Dispose() { if (_client != null) { _client.Dispose(); } }
public async Task IgniteAsync() { _karma = new KarmaService(_client); _client.MessageReceived += HandleMessageCreatedAsync; _client.UserJoined += HandleMemberJoinedAsync; _client.Ready += async() => { await _client.SetGameAsync("the fireworks", type : ActivityType.Watching); _poller = new Poller(this, _client); }; _client.Log += LogAsync; _commands.Log += LogAsync; await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); await _client.LoginAsync(TokenType.Bot, Configuration.Get <string>("token")); await _client.StartAsync(); await Task.Delay(-1, _cts.Token) .ContinueWith(async task => { await _client.StopAsync(); await _client.LogoutAsync(); _client.Dispose(); }); }
public async Task MainAsync() { _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Info }); _client.Log += Log; _client.Ready += async() => { IsLoaded = true; }; try { await _client.LoginAsync(TokenType.Bot, _token); await _client.StartAsync(); } catch (HttpException e) { _Core.WriteLog("연결을 할 수 없습니다 : " + e); _client.Dispose(); } await Task.Delay(-1); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _discordClient.Dispose(); _serviceProvider.Dispose(); } _discordClient.Log -= LogDiscord; _discordClient.Ready -= OnDiscordClientReady; _commandService.Log -= LogDiscord; _discordClient.MessageReceived -= HandleCommandAsync; _commandService = null; _discordClient = null; _serviceProvider = null; _settings = null; _disposed = true; }
private static async Task MainAsync(string[] args) { WriteLog("demarrage BOT..."); try { using (client = new DiscordSocketClient()) { client.Log += BotLog; client.MessageReceived += OnMessageReceived; client.Ready += Client_Ready; await client.LoginAsync(Discord.TokenType.Bot, "NjMxNDk0MDA1OTM0NTIyMzg4.XaCO9g.SNDyoXPa4iik7rlHfn_WLK1fE1Y"); await client.StartAsync(); await Task.Delay(-1); } } catch (Exception e) { WriteError(e.ToString(), "MainAsyncException_0x1"); PConsole.QuitWithAsk(); } finally { client?.Dispose(); } }
public async Task RunBotAsync() { try { if (Config.bot.token == "" || Config.bot.token == null) { return; } _client?.Dispose(); _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Verbose, }); await InitializationClient(); await InitializationLogs(); ConsoleInput(); await Task.Delay(-1); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } }
public void Dispose() { DiscordClient.LogoutAsync().Wait(); DiscordClient.StopAsync().Wait(); DiscordClient.Dispose(); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { client?.Dispose(); disposedValue = true; } }
/// <summary> /// Disposes of the discord client /// </summary> public async void Dispose() { await _client.LogoutAsync(); _client.Dispose(); _client = null; GC.SuppressFinalize(this); }
/// <summary> /// Dispose the object /// </summary> public void Dispose() { if (m_Client != null) { m_Client.Dispose(); m_Client = null; } }
public async ValueTask DisposeAsync() { client?.Dispose(); if (updateRaidsTimer != null) { await updateRaidsTimer.DisposeAsync(); } }
private static async Task Exit(DiscordSocketClient bot) { await bot.StopAsync(); bot.Dispose(); _isWorking = false; Environment.Exit(0); }
private static async Task StopAsync() { await _client.LogoutAsync(); await _client.StopAsync(); _client.Dispose(); }
public void Dispose() { if (channelMessageCallback != null) { client.MessageReceived -= channelMessageCallback; } client.Dispose(); }
public async void Stop() { await _client.LogoutAsync(); await _client.StopAsync(); _client.Dispose(); // cts?.Cancel(); }
public async Task MainAsync() { await _discordClient.LoginAsync(TokenType.Bot, File.ReadAllText(TokenLocation)).ConfigureAwait(true); await _discordClient.StartAsync().ConfigureAwait(true); // Block the program until it is closed. while (true) { var line = Console.ReadLine(); //user wants to exit if (line == "exit") { break; } //Recheck //TODO: Clean this up, its so ugly if (line == "recheck") { var serverNonReacts = await GetNonReactUsersAsync(ServerRulesId, ServerRulesMessageId).ConfigureAwait(true); //TODO: My mind is burnt out right now, i was gonna do something with this earlier //var tenManNonReacts = await GetNonReactUsers(TenManRulesId, TenManRulesMessageId).ConfigureAwait(true); var visitorRole = GetSocketRoleFromId(VisitorRoleId); foreach (var x in serverNonReacts) { if (x.IsBot) { continue; } var fUser = _guild.Users.First(y => y.Id == x.Id); if (fUser.Roles.Count == 2 && fUser.Roles.Contains(visitorRole)) { continue; } var guildUser = _guild.GetUser(fUser.Id); foreach (var r in guildUser.Roles) { if (r.IsEveryone) { continue; } await RoleAssigner.RemoveRoleAsync(guildUser, r).ConfigureAwait(true); } await RoleAssigner.AssignRoleAsync(x.Id, VisitorRoleId).ConfigureAwait(true); } } } _discordClient.Dispose(); }
public void Stop() { if (_connected) { _client.LogoutAsync(); _client.StopAsync(); } _client.Dispose(); }
public void Dispose() { //remove event handlers to keep things clean on dispose _commands.CommandExecuted -= CommandExecutedAsync; _discord.MessageReceived -= MessageReceivedAsync; _discord.ReactionAdded -= ReactionAddedAsync; ((IDisposable)_commands)?.Dispose(); _discord?.Dispose(); }
/// <summary> /// Shutsdown and disposes <see cref="client"/> /// </summary> void DisconnectAndDispose() { try { client.StopAsync().Wait(); client.LogoutAsync().Wait(); } catch { } client.Dispose(); }
private static async Task Reconnect(Exception e) { Logger.Info("Disconnected from Discord"); if (e != null) { Logger.Error(e); } _socket.Dispose(); await Connect(); }
public void Dispose() { _bot.LogoutAsync(); while (_bot.LoginState == LoginState.LoggingOut) { Thread.Sleep(1); } _bot.StopAsync(); _bot.Dispose(); }
public async Task StopAsync(CancellationToken cancellationToken) { if (client != null) { await client.StopAsync(); client.Dispose(); client = null; } }
public void Dispose() { Disconnect(); _voiceChannelService?.Dispose(); _client.Dispose(); _client = null; _bufferBytes = null; _voiceChannelService = null; _token = null; _voiceBuffer = null; }
private static async void CleanMemory(object source, ElapsedEventArgs e) { GC.Collect(); if (Math.Round(GC.GetTotalMemory(true) / (1024.0 * 1024.0), 2) > 1024) { await Client.LogoutAsync(); Client.Dispose(); Main(null); } }
// Defined within this class because a reference to the client is required public void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; Logger.GetLogger("Runtime")("Caught cancel key. Will attempt to disconnect...").Wait(); _client.LogoutAsync().Wait(); _client.Dispose(); #if DEBUG Console.WriteLine("Press enter to exit."); Console.ReadLine(); #endif Environment.Exit(0); }
private async Task DiscordRestClient_LoggedOut() { CurrentUser = null; await DiscordSocketClient.LogoutAsync(); DiscordSocketClient.Dispose(); DiscordSocketClient = null; CurrentVoiceChannel = null; CurrentTextChannel = null; CurrentGuild = null; }
public void Dispose() { CancellationTokenSource?.Dispose(); _client?.Dispose(); _configDataAccess?.Dispose(); _justJumpDataAccess?.Dispose(); _simplyHightowerDataAccess?.Dispose(); _todoDataAccess?.Dispose(); _intervalFunctionTimer?.Dispose(); }
public async Task StopAsync(CancellationToken cancellationToken) { await SendBotSpamMessage(client, "Bot stoppt..."); _logger.LogInformation("Ausloggen."); await client.LogoutAsync(); _logger.LogInformation("Verbindung trennen."); await client.StopAsync(); client.Dispose(); }