From 3c6d677f85ac7ce119bf7185043f79b540c8a10f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 9 Jan 2017 21:25:03 -0500 Subject: [PATCH] Update README example. --- README.md | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index fb324b86d..4502770a1 100644 --- a/README.md +++ b/README.md @@ -56,29 +56,28 @@ Please note that on Linux installing voice you must install the following packag import discord import asyncio -client = discord.Client() - -@client.event -async def on_ready(): - print('Logged in as') - print(client.user.name) - print(client.user.id) - print('------') - -@client.event -async def on_message(message): - if message.content.startswith('!test'): - counter = 0 - tmp = await client.send_message(message.channel, 'Calculating messages...') - async for log in client.logs_from(message.channel, limit=100): - if log.author == message.author: - counter += 1 - - await client.edit_message(tmp, 'You have {} messages.'.format(counter)) - elif message.content.startswith('!sleep'): - await asyncio.sleep(5) - await client.send_message(message.channel, 'Done sleeping') - +class MyClient(discord.Client): + async def on_ready(self): + print('Logged in as') + print(self.user.name) + print(self.user.id) + print('------') + + async def on_message(self, message): + if message.content.startswith('!test'): + counter = 0 + tmp = await message.channel.send('Calculating messages...') + async for msg in message.channel.history(limit=100): + if msg.author == message.author: + counter += 1 + + await tmp.edit(content='You have {} messages.'.format(counter)) + elif message.content.startswith('!sleep'): + with message.channel.typing(): + await asyncio.sleep(5.0) + await message.channel.send('Done sleeping.') + +client = MyClient() client.run('token') ```