diff options
| author | Rapptz <[email protected]> | 2015-12-12 13:37:58 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-12 13:37:58 -0500 |
| commit | 2b6bdf7c8258e426cc448d5035a3557a904c0a5e (patch) | |
| tree | f8dedae5ec23961d1988591ffa4a7dfc6eb9a47a | |
| parent | Fix send_file to actually work with aiohttp. (diff) | |
| download | discord.py-2b6bdf7c8258e426cc448d5035a3557a904c0a5e.tar.xz discord.py-2b6bdf7c8258e426cc448d5035a3557a904c0a5e.zip | |
Fix bug where PMs would be sent to the wrong person.
This bug triggered because we did not call `yield from` to the
coroutine that starts the private message if it isn't found in cache.
Obviously the fix for that is to make the destination resolution a
coroutine and thus it'll be invoked correctly.
| -rw-r--r-- | discord/client.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/discord/client.py b/discord/client.py index a1c79bab..5674b33f 100644 --- a/discord/client.py +++ b/discord/client.py @@ -170,6 +170,7 @@ class Client: return m.group(1) return invite + @asyncio.coroutine def _resolve_destination(self, destination): if isinstance(destination, (Channel, PrivateChannel, Server)): return destination.id @@ -177,7 +178,7 @@ class Client: found = utils.find(lambda pm: pm.user == destination, self.private_channels) if found is None: # Couldn't find the user, so start a PM with them first. - self.start_private_message(destination) + yield from self.start_private_message(destination) channel_id = self.private_channels[-1].id return channel_id else: @@ -758,7 +759,7 @@ class Client: The message that was sent. """ - channel_id = self._resolve_destination(destination) + channel_id = yield from self._resolve_destination(destination) content = str(content) mentions = self._resolve_mentions(content, mentions) @@ -796,7 +797,7 @@ class Client: The location to send the typing update. """ - channel_id = self._resolve_destination(destination) + channel_id = yield from self._resolve_destination(destination) url = '{base}/{id}/typing'.format(base=endpoints.CHANNELS, id=channel_id) @@ -847,7 +848,7 @@ class Client: The message sent. """ - channel_id = self._resolve_destination(destination) + channel_id = yield from self._resolve_destination(destination) url = '{base}/{id}/messages'.format(base=endpoints.CHANNELS, id=channel_id) files = aiohttp.FormData() |