aboutsummaryrefslogtreecommitdiff
path: root/discord/client.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-11-04 00:02:03 -0400
committerRapptz <[email protected]>2016-11-04 00:02:25 -0400
commitedcd1750c9c1bf4d35036ff818f9ce665daf5acb (patch)
treef0f3aca1a44b53ef38689250b79ca72fc03db744 /discord/client.py
parentFix Reaction not importing. (diff)
downloaddiscord.py-edcd1750c9c1bf4d35036ff818f9ce665daf5acb.tar.xz
discord.py-edcd1750c9c1bf4d35036ff818f9ce665daf5acb.zip
Make Client.wait_for_reaction return a namedtuple instead.
Also fix a bug in the case that emoji parameter is `None`.
Diffstat (limited to 'discord/client.py')
-rw-r--r--discord/client.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/discord/client.py b/discord/client.py
index 7c597542..f9888fe7 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -61,6 +61,8 @@ PY35 = sys.version_info >= (3, 5)
log = logging.getLogger(__name__)
AppInfo = namedtuple('AppInfo', 'id name description icon owner')
+WaitedReaction = namedtuple('WaitedReaction', 'reaction user')
+
def app_info_icon_url(self):
"""Retrieves the application's icon_url if it exists. Empty string otherwise."""
if not self.icon:
@@ -215,7 +217,7 @@ class Client:
removed.append(i)
else:
if result:
- future.set_result((reaction, user))
+ future.set_result(WaitedReaction(reaction, user))
removed.append(i)
@@ -770,10 +772,24 @@ class Client:
async def on_message(message):
if message.content.startswith('$react'):
msg = await client.send_message(message.channel, 'React with thumbs up or thumbs down.')
- (reaction, user) = await client.wait_for_reaction(['\N{THUMBS UP SIGN}',
- '\N{THUMBS DOWN SIGN}'],
- message=msg)
- await client.send_message(message.channel, '{} reacted with {.emoji}!'.format(user, reaction))
+ res = await client.wait_for_reaction(['\N{THUMBS UP SIGN}', '\N{THUMBS DOWN SIGN}'], message=msg)
+ await client.send_message(message.channel, '{.user} reacted with {.reaction.emoji}!'.format(res))
+
+ Checking for reaction emoji regardless of skin tone:
+
+ .. code-block:: python
+
+ @client.event
+ async def on_message(message):
+ if message.content.startswith('$react'):
+ msg = await client.send_message(message.channel, 'React with thumbs up or thumbs down.')
+
+ def check(reaction, user):
+ e = str(reaction.emoji)
+ return e.startswith(('\N{THUMBS UP SIGN}', '\N{THUMBS DOWN SIGN}'))
+
+ res = await client.wait_for_reaction(message=msg, check=check)
+ await client.send_message(message.channel, '{.user} reacted with {.reaction.emoji}!'.format(res))
Parameters
-----------
@@ -793,12 +809,13 @@ class Client:
Returns
--------
- tuple
- A tuple of ``(reaction, user)`` similar to :func:`on_reaction_add`.
+ namedtuple
+ A namedtuple with attributes ``reaction`` and ``user`` similar to :func:`on_reaction_add`.
"""
- emoji_check = lambda r: True
- if isinstance(emoji, (str, Emoji)):
+ if emoji is None:
+ emoji_check = lambda r: True
+ elif isinstance(emoji, (str, Emoji)):
emoji_check = lambda r: r.emoji == emoji
else:
emoji_check = lambda r: r.emoji in emoji