mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-13 09:19:48 +00:00
Update README to use Python 3.5.
This commit is contained in:
parent
2ebfbbe471
commit
85ceeb5efc
32
README.md
32
README.md
@ -50,41 +50,33 @@ import asyncio
|
|||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
@client.async_event
|
@client.event
|
||||||
def on_ready():
|
async def on_ready():
|
||||||
print('Logged in as')
|
print('Logged in as')
|
||||||
print(client.user.name)
|
print(client.user.name)
|
||||||
print(client.user.id)
|
print(client.user.id)
|
||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
@client.async_event
|
@client.event
|
||||||
def on_message(message):
|
async def on_message(message):
|
||||||
if message.content.startswith('!test'):
|
if message.content.startswith('!test'):
|
||||||
logs = yield from client.logs_from(message.channel, limit=100)
|
logs = await client.logs_from(message.channel, limit=100)
|
||||||
counter = 0
|
counter = 0
|
||||||
tmp = yield from client.send_message(message.channel, 'Calculating messages...')
|
tmp = await client.send_message(message.channel, 'Calculating messages...')
|
||||||
for log in logs:
|
for log in logs:
|
||||||
if log.author == message.author:
|
if log.author == message.author:
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
yield from client.edit_message(tmp, 'You have {} messages.'.format(counter))
|
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
|
||||||
elif message.content.startswith('!sleep'):
|
elif message.content.startswith('!sleep'):
|
||||||
yield from asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
yield from client.send_message(message.channel, 'Done sleeping')
|
await client.send_message(message.channel, 'Done sleeping')
|
||||||
|
|
||||||
def main_task():
|
client.run('email', 'password')
|
||||||
yield from client.login('email', 'password')
|
|
||||||
yield from client.connect()
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
try:
|
|
||||||
loop.run_until_complete(main_task())
|
|
||||||
except Exception:
|
|
||||||
loop.run_until_complete(client.close())
|
|
||||||
finally:
|
|
||||||
loop.close()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that in Python 3.4 you use `@asyncio.coroutine` instead of `async def` and `yield from` instead of `await`.
|
||||||
|
|
||||||
You can find examples in the examples directory.
|
You can find examples in the examples directory.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
Loading…
x
Reference in New Issue
Block a user