From 01765174537f3ff0807128745c14a1fac525f23e Mon Sep 17 00:00:00 2001 From: Khazhismel Date: Sun, 29 Nov 2015 21:08:24 -0500 Subject: [PATCH] Provide server/channel id/name as Object if client not joined to server. --- discord/client.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/discord/client.py b/discord/client.py index b984b5afa..3ef13ca4e 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1160,8 +1160,9 @@ class Client(object): .. note:: - If the server attribute of the returned invite is ``None`` then that means - that you have not joined the server. + If the invite is for a server you have not joined, the server and channel + attributes of the returned invite will be :class:`Object` with the names + patched in. """ @@ -1172,10 +1173,17 @@ class Client(object): utils._verify_successful_response(response) data = response.json() server = self.connection._get_server(data['guild']['id']) + if server is not None: + ch_id = data['channel']['id'] + channels = getattr(server, 'channels', []) + channel = utils.find(lambda c: c.id == ch_id, channels) + else: + server = Object(id=data['guild']['id']) + server.name = data['guild']['name'] + channel = Object(id=data['channel']['id']) + channel.name = data['channel']['name'] data['server'] = server - ch_id = data['channel']['id'] - channels = getattr(server, 'channels', []) - data['channel'] = utils.find(lambda c: c.id == ch_id, channels) + data['channel'] = channel return Invite(**data) def accept_invite(self, invite): @@ -1458,4 +1466,3 @@ class Client(object): sent = json.dumps(payload) log.debug('Sending "{}" to change status'.format(sent)) self.ws.send(sent) -