{"action":"closed","issue":{"url":"https://api.github.com/repos/hydrabolt/discord.js/issues/276","repository_url":"https://api.github.com/repos/hydrabolt/discord.js","labels_url":"https://api.github.com/repos/hydrabolt/discord.js/issues/276/labels{/name}","comments_url":"https://api.github.com/repos/hydrabolt/discord.js/issues/276/comments","events_url":"https://api.github.com/repos/hydrabolt/discord.js/issues/276/events","html_url":"https://github.com/hydrabolt/discord.js/issues/276","id":148919241,"number":276,"title":"Use of client.logout() with autoReconnect looping disconnected event and not working for long disconnects","user":{"login":"BrunoMoreira991","id":16598818,"avatar_url":"https://avatars.githubusercontent.com/u/16598818?v=3","gravatar_id":"","url":"https://api.github.com/users/BrunoMoreira991","html_url":"https://github.com/BrunoMoreira991","followers_url":"https://api.github.com/users/BrunoMoreira991/followers","following_url":"https://api.github.com/users/BrunoMoreira991/following{/other_user}","gists_url":"https://api.github.com/users/BrunoMoreira991/gists{/gist_id}","starred_url":"https://api.github.com/users/BrunoMoreira991/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrunoMoreira991/subscriptions","organizations_url":"https://api.github.com/users/BrunoMoreira991/orgs","repos_url":"https://api.github.com/users/BrunoMoreira991/repos","events_url":"https://api.github.com/users/BrunoMoreira991/events{/privacy}","received_events_url":"https://api.github.com/users/BrunoMoreira991/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hydrabolt/discord.js/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-17T05:06:51Z","updated_at":"2016-04-23T01:22:06Z","closed_at":"2016-04-23T01:22:06Z","body":"After using `client.logout()` with `autoReconnect` as **true** the `disconnected` event will keep firing and loop forever.\r\n![disconnected loop](https://cloud.githubusercontent.com/assets/16598818/14585162/62ad4f84-0462-11e6-8cf0-da76ed1681c6.png)\r\n\r\n---\r\n**EDIT**: After further testing I confirmed that `autoReconnect` is only working for really short timeouts.\r\n```Javascript\r\n//I made this little console.logs to make sure.\r\nif (autoReconnect) {\r\n    this.autoReconnectInterval = Math.min(this.autoReconnectInterval * (Math.random() + 1), 60000);\r\n    console.log(\"autoReconnectInterval is \" + this.autoReconnectInterval);\r\n    setTimeout(function () {\r\n        console.log(\"I got here\");\r\n        _this2.setup();\r\n\r\n        // Check whether the email is set (if not, only a token has been used for login)\r\n        if (_this2.email) {\r\n            _this2.login(_this2.email, _this2.password);\r\n        } else {\r\n            _this2.loginWithToken(_this2.token);\r\n        }\r\n    }, this.autoReconnectInterval);\r\n}\r\n```\r\n![autoreconnect issue](https://cloud.githubusercontent.com/assets/16598818/14589423/f5c35224-04d9-11e6-81ac-cce430c4d4f2.png)\r\n\r\n> First disconnect is a really short timeout (Internet came back almost at the same time the disconnected event was fired) and the second disconnect was a longer one.\r\n\r\n1. Bot Disconnects (Internet goes down or whatever)\r\n2. Tries to login (autoReconnect)\r\n3. Fails because there is no Internet yet or whatever.\r\n4. Doesn't retry.\r\n\r\n---\r\n1. client.logout()\r\n2. Tries to login (autoReconnect)\r\n3. Fails because there are no credentials due to logout()\r\n4. Keeps trying.\r\n\r\nThe \"papers\" are inversed. lol"}}