Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import discord
  2. from discord.ext.commands import Bot
  3. from discord.ext import commands
  4. import asyncio
  5. import time
  6. import random
  7.  
  8.  
  9. Client = discord.Client() #Initialise Client
  10. client = commands.Bot(command_prefix = "<prefix>") #Initialise client bot
  11.  
  12.  
  13. @client.event
  14. async def on_message(message):
  15. if message.content.upper().startswith('<prefix>GUESS'): #Replace <prefix> with your bot prefix
  16. userID = message.author.name
  17. await client.send_message(message.channel, ':question: | Guess a number between 1 to 10, **%s**' % (userID))
  18.  
  19. def guess_check(m):
  20. return m.content.isdigit()
  21.  
  22. guess = await client.wait_for_message(timeout=5.0, author=message.author, check=guess_check)
  23. answer = random.randint(1, 10)
  24. if guess is None:
  25. fmt = ':question: | Sorry, you took too long. It was {}.'
  26. await client.send_message(message.channel, fmt.format(answer))
  27. return
  28. if int(guess.content) == answer:
  29. await client.send_message(message.channel, ':question: | You are right, **%s**!' % (userID))
  30. else:
  31. await client.send_message(message.channel, ':question: | Sorry. It is actually {}, **%s**.'.format(answer) % (userID))
  32.  
  33.  
  34. client.run("<token>") #Insert your bots token here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement