forked from usacs/Self-Guided-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek1.py
More file actions
30 lines (25 loc) · 949 Bytes
/
week1.py
File metadata and controls
30 lines (25 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import discord
import asyncio
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):
# don't respond to ourselves
if message.author == self.user:
return
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')