aboutsummaryrefslogtreecommitdiff
path: root/discord/state.py
diff options
context:
space:
mode:
authorSteven Berler <[email protected]>2015-12-12 13:21:44 -0800
committerRapptz <[email protected]>2015-12-13 13:01:05 -0500
commit037da750dd700fa3df6147e76d9f1344f6620a48 (patch)
treec38393a68fa2f9b3d3d41b086eaf8ef13a137fcc /discord/state.py
parentRemove uses of ClientSession. (diff)
downloaddiscord.py-037da750dd700fa3df6147e76d9f1344f6620a48.tar.xz
discord.py-037da750dd700fa3df6147e76d9f1344f6620a48.zip
avoid potential bug when creating new private msgs
It probably isn't good to rely on an item that was added to a list to still be the last item, especially if we could have other async coroutines modify the list. This may not be an actual issue, but having the function explicitly return the object that it just added to the list should guarantee that we don't accidentally pull the wrong item from the end of the list later.
Diffstat (limited to 'discord/state.py')
-rw-r--r--discord/state.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/discord/state.py b/discord/state.py
index 65ba008c..17b68314 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -55,6 +55,7 @@ class ConnectionState:
def _add_server(self, guild):
server = Server(**guild)
self.servers.append(server)
+ return server
def parse_ready(self, data):
self.user = User(**data['user'])
@@ -220,8 +221,8 @@ class ConnectionState:
# unavailable during the READY event and is now
# available, so it isn't in the cache...
- self._add_server(data)
- self.dispatch('server_join', self.servers[-1])
+ server = self._add_server(data)
+ self.dispatch('server_join', server)
def parse_guild_update(self, data):
server = self._get_server(data.get('id'))