blob: 550fa18576ac9d20339d72ba7f1342da9631bde2 (
plain) (
blame)
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
|
import discord
import random
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):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
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)
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')
|