         (swap! bots dissoc bot)))))
 
 (defn connect [params]
-  (let [{:keys [token functions log-events? log-function max-text-message-size bot]
+  (let [{:keys [token functions log-events? log-function max-text-message-size bot rate-limit]
          :or {functions {}
               log-events? true
               log-function (fn [& args] (println "\n" args))
               max-text-message-size (* 64 1024)
+              rate-limit 5000
               bot (swap! previous-bot inc)}} params
         token (if (.startsWith token "Bot ") (.trim token) (str "Bot " (.trim token)))
         params {:token token

                :log-events? log-events?
                :log-function log-function
                :max-text-message-size max-text-message-size
                :bot bot}

        websocket-client (new WebSocketClient (new SslContextFactory))
        heartbeat-thread (Thread. (fn []

    bot))

(defn check-rate-limit [bot]
  (let [now (System/currentTimeMillis)
        previous-activity (:activity (get @bots bot))
        previous-activity (if (nil? previous-activity) 0 previous-activity)
        millis-since-previous-activity (- now previous-activity)
        rate-limit (-> (get @bots bot) :params :rate-limit)]
    (if
      (> rate-limit millis-since-previous-activity)
      false
      (do
        (swap! bots update-in [bot] assoc :activity now)
