-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
57 lines (42 loc) · 1.36 KB
/
game.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
48
49
50
51
52
53
54
55
56
57
import random
import discord
from discord.ext import commands
TOKEN = "paste_your_token_here"
PREFIX = "!"
LOWEST_NUMBER = 1
HIGHEST_NUMBER = 100
bot = commands.Bot(command_prefix=PREFIX)
numbers = {}
@bot.event
async def on_ready():
print("Bot ready!")
@bot.event
async def on_message(message):
await bot.process_commands(message)
@bot.command()
async def start(ctx):
user_id = str(ctx.message.author.id)
if user_id in numbers:
await ctx.send("Already in a game!")
return
random_number = random.randint(LOWEST_NUMBER, HIGHEST_NUMBER + 1)
numbers[user_id] = random_number
await ctx.send(f"I'm thinking of a number between {LOWEST_NUMBER} and {HIGHEST_NUMBER}\nType `!guess (number)` to make guesses!")
print(numbers)
@bot.command()
async def guess(ctx):
user_id = str(ctx.message.author.id)
if user_id not in numbers:
await ctx.send("You are not in a game yet! Use `!start` to begin one.")
return
guessed_number = int(ctx.message.content.split(' ')[1])
actual_number = numbers[user_id]
if guessed_number > actual_number:
await ctx.send("Too high!")
elif guessed_number < actual_number:
await ctx.send("Too low!")
else:
await ctx.send(f"Correctly guessed, the number is {actual_number}!")
del numbers[user_id]
print('\x1b[2J\nBot starting...')
bot.run(TOKEN)