mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Update examples to use the new generic wait_for.
This commit is contained in:
parent
e5cb7d295c
commit
1e09432c45
@ -15,7 +15,7 @@ class MyClient(discord.Client):
|
|||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
async def my_background_task(self):
|
async def my_background_task(self):
|
||||||
await self.wait_until_ready()
|
await self.wait_for('ready')
|
||||||
counter = 0
|
counter = 0
|
||||||
channel = self.get_channel(1234567) # channel ID goes here
|
channel = self.get_channel(1234567) # channel ID goes here
|
||||||
while not self.is_closed:
|
while not self.is_closed:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import discord
|
import discord
|
||||||
import random
|
import random
|
||||||
|
import asyncio
|
||||||
|
|
||||||
class MyClient(discord.Client):
|
class MyClient(discord.Client):
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
@ -15,13 +16,16 @@ class MyClient(discord.Client):
|
|||||||
|
|
||||||
if message.content.startswith('$guess'):
|
if message.content.startswith('$guess'):
|
||||||
await message.channel.send('Guess a number between 1 and 10.')
|
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)
|
answer = random.randint(1, 10)
|
||||||
if guess is not None:
|
|
||||||
await message.channel.send('Sorry, you took too long it was {}.'.format(answer))
|
try:
|
||||||
return
|
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:
|
if int(guess.content) == answer:
|
||||||
await message.channel.send('You are right!')
|
await message.channel.send('You are right!')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user