aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-12-16 21:36:39 -0500
committerRapptz <[email protected]>2017-12-16 21:36:39 -0500
commit5c5a59c18e41538bee44ed85b7cf1806e830623d (patch)
tree42a29138793346c93df4c8d0d97214619dc4a0ea
parentUpdate README to point to new server. (diff)
downloaddiscord.py-5c5a59c18e41538bee44ed85b7cf1806e830623d.tar.xz
discord.py-5c5a59c18e41538bee44ed85b7cf1806e830623d.zip
Add Client.clear to clear the bot's internal state to a clean slate.
In case you want to have some external restart loop.
-rw-r--r--discord/client.py12
-rw-r--r--discord/http.py4
2 files changed, 16 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index deede9cc..1bc06d90 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -462,6 +462,18 @@ class Client:
yield from self.http.close()
self._ready.clear()
+ def clear(self):
+ """Clears the internal state of the bot.
+
+ After this, the bot can be considered "re-opened", i.e. :meth:`.is_closed`
+ and :meth:`.is_ready` both return ``False`` along with the bot's internal
+ cache cleared.
+ """
+ self._closed.clear()
+ self._ready.clear()
+ self._connection.clear()
+ self._http.recreate()
+
@asyncio.coroutine
def start(self, *args, **kwargs):
"""|coro|
diff --git a/discord/http.py b/discord/http.py
index 70d47424..7ec64d82 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -102,6 +102,10 @@ class HTTPClient:
user_agent = 'DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}'
self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
+ def recreate(self):
+ if self._session.closed:
+ self._session = aiohttp.ClientSession(connector=self.connector, loop=self.loop)
+
@asyncio.coroutine
def request(self, route, *, header_bypass_delay=None, **kwargs):
bucket = route.bucket