From 2b6bdf7c8258e426cc448d5035a3557a904c0a5e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 12 Dec 2015 13:37:58 -0500 Subject: [PATCH] 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. --- discord/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/discord/client.py b/discord/client.py index a1c79babb..5674b33f0 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()