private async Task MainAsync(string[] args)
        {
            Utils.InitFemaleSpriteLookup();
            ReplaySaver.RemoveOldReplays();
            PBEUtils.InitEngine(string.Empty);

            _client = new DiscordSocketClient();

            _commands = new CommandService(new CommandServiceConfig {
                DefaultRunMode = RunMode.Async
            });
            await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), null);

            _client.Log                += LogMessage;
            _client.MessageReceived    += CommandMessageReceived;
            _client.ReactionAdded      += OnReactionAdded;
            _client.ChannelDestroyed   += OnChannelDeleted;
            _client.LeftGuild          += OnLeftGuild;
            _client.UserLeft           += OnUserLeft;
            _client.Connected          += OnConnected;
            _client.Disconnected       += OnDisconnected;
            _client.GuildMemberUpdated += OnGuildMemberUpdated;

            await _client.LoginAsync(TokenType.Bot, args[0]); // Token is passed in as args[0]

            await _client.StartAsync();

            await Task.Delay(-1);
        }
 private void CloseSilent(bool saveReplay)
 {
     lock (_activeBattlesLockObj)
     {
         _activeBattles.Remove(this);
         if (_battler0 != null)
         {
             _activeBattlers.Remove(_battler0);
         }
         if (_battler1 != null)
         {
             _activeBattlers.Remove(_battler1);
         }
         _activeChannels.Remove(_channel);
         _activeGuilds[_channel.Guild].Remove(this);
         // Only save replay if ((saveReplay is true) and (not battling an AI or (battling an AI and should save AI replays)))
         if (saveReplay && ((_battler0 != null && _battler1 != null) || ReplaySaver.ShouldSaveAIBattles))
         {
             ReplaySaver.SaveReplay(_battle, BattleId); // Save battle in the lock so they don't conflict while directory checking
         }
     }
     _battle.OnNewEvent     -= Battle_OnNewEvent;
     _battle.OnStateChanged -= Battle_OnStateChanged;
     ReactionHandler.RemoveListeners(_battler0, _battler1);
 }