aboutsummaryrefslogtreecommitdiff
path: root/examples/guessing_game.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-01-26 04:30:26 -0500
committerRapptz <[email protected]>2017-01-26 04:30:47 -0500
commit1e09432c45054d0bef7a0fd4d2158d4e14f8f657 (patch)
tree4d89938b3f3cfbcd0449098afb91e5817bfae99f /examples/guessing_game.py
parentReplace wait_for_* with a generic Client.wait_for (diff)
downloaddiscord.py-1e09432c45054d0bef7a0fd4d2158d4e14f8f657.tar.xz
discord.py-1e09432c45054d0bef7a0fd4d2158d4e14f8f657.zip
Update examples to use the new generic wait_for.
Diffstat (limited to 'examples/guessing_game.py')
-rw-r--r--examples/guessing_game.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/guessing_game.py b/examples/guessing_game.py
index 550fa185..a8f09c63 100644
--- a/examples/guessing_game.py
+++ b/examples/guessing_game.py
@@ -1,5 +1,6 @@
import discord
import random
+import asyncio
class MyClient(discord.Client):
async def on_ready(self):
@@ -15,13 +16,16 @@ class MyClient(discord.Client):
if message.content.startswith('$guess'):
await message.channel.send('Guess a number between 1 and 10.')
- check = lambda m: m.content.isdigit()
- guess = await self.wait_for_message(author=message.author, check=check, timeout=5.0)
+
+ def is_correct(m):
+ return m.author == message.author and m.content.isdigit()
answer = random.randint(1, 10)
- if guess is not None:
- await message.channel.send('Sorry, you took too long it was {}.'.format(answer))
- return
+
+ try:
+ guess = await self.wait_for('message', check=is_correct, timeout=5.0)
+ except asyncio.TimeoutError:
+ return await message.channel.send('Sorry, you took too long it was {}.'.format(answer))
if int(guess.content) == answer:
await message.channel.send('You are right!')