Update examples to match the new rewrite API.

This commit is contained in:
Rapptz
2017-01-03 20:57:41 -05:00
parent 94655c77c0
commit f8a5d890fe
7 changed files with 109 additions and 120 deletions

View File

@ -1,37 +1,32 @@
import discord
import random
client = discord.Client()
class MyClient(discord.Client):
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('$guess'):
await client.send_message(message.channel, 'Guess a number between 1 to 10')
def guess_check(m):
return m.content.isdigit()
guess = await client.wait_for_message(timeout=5.0, author=message.author, check=guess_check)
answer = random.randint(1, 10)
if guess is None:
fmt = 'Sorry, you took too long. It was {}.'
await client.send_message(message.channel, fmt.format(answer))
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
if int(guess.content) == answer:
await client.send_message(message.channel, 'You are right!')
else:
await client.send_message(message.channel, 'Sorry. It is actually {}.'.format(answer))
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)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
answer = random.randint(1, 10)
if guess is not None:
await message.channel.send('Sorry, you took too long it was {}.'.format(answer))
return
if int(guess.content) == answer:
await message.channel.send('You are right!')
else:
await message.channel.send('Oops. It is actually {}.'.format(answer))
client = MyClient()
client.run('token')