【发布时间】:2021-08-25 14:03:24
【问题描述】:
我正在用 python 制作一个猜谜游戏机器人,但多个人可以同时使用该机器人。我可以一次将其限制为一个可以使用该机器人的人吗?我希望得到一些相对容易理解的东西(如果可能的话)。
(我是 python 的初学者)
import keep_alive
import discord
import os
from discord.ext import commands
import random
import sys
client = commands.Bot(command_prefix=".")
number = random.randint(1, 100)
@client.event
async def on_ready():
print("The bot is online")
@client.command()
async def numpuz(ctx):
global steps
await ctx.send("Type a starting number")
steps = 0
steps = 1
global number
print(number)
global lives
lives = 8
@client.command()
async def num(ctx, guessednumber):
global steps
global number
global lives
if int(guessednumber) > number:
if steps == 1:
await ctx.send("Try again you were to high")
lives = lives - 1
if lives == 0:
await ctx.send("YOU LOST")
steps = 0
elif int(guessednumber) < number:
if steps == 1:
await ctx.send("Try again you were to low")
lives = lives - 1
if lives == 0:
await ctx.send("YOU LOST")
steps = 0
else:
if steps == 1:
await ctx.send("YOU WON")
steps = 0
number = random.randint(1, 100)
await ctx.send("You had " +str(lives)+ " lives left")
comm.reset_cooldown(ctx)
keep_alive.keep_alive()
client.run(os.getenv("token"))
【问题讨论】: