-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorsikguess.py
47 lines (36 loc) · 1.27 KB
/
orsikguess.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import discord
import random
client = discord.Client()
def gettoken(file):
with open(file) as f:
for line in f:
token=str(line)
return token
@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))
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))
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
await client.send_message('Orsik Guessing Game')
token=gettoken("orsiktoken")
client.run(token)