diff options
| author | Khazhismel <[email protected]> | 2015-11-29 21:08:24 -0500 |
|---|---|---|
| committer | Khazhismel <[email protected]> | 2015-11-29 21:58:17 -0500 |
| commit | 01765174537f3ff0807128745c14a1fac525f23e (patch) | |
| tree | c9cd54f2af6c37ba0c561848c49b5bd359e45350 | |
| parent | Version bump to v0.9.0 (diff) | |
| download | discord.py-01765174537f3ff0807128745c14a1fac525f23e.tar.xz discord.py-01765174537f3ff0807128745c14a1fac525f23e.zip | |
Provide server/channel id/name as Object if client not joined to server.
| -rw-r--r-- | discord/client.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/discord/client.py b/discord/client.py index b984b5af..3ef13ca4 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) - |