You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
import discord
|
|
import random
|
|
|
|
client = discord.Client()
|
|
|
|
@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('------')
|
|
|
|
client.run('token')
|
|
|