【发布时间】:2022-01-26 17:40:50
【问题描述】:
我尝试使用time.sleep(),但没有等待变量,而是暂停了整个代码,不允许变量更改。
这是我的代码:
@tasks.loop(seconds=5.0) #This is the code that changes the variable (Before this block of code, the variable fedex is defined)
global check, fedex
fedex = int(fedex) + r.randint(-500,500)
if(check=="0"):
check = "1"
else:
check = "0"
@client.command() #This is the code in which, after the variable changes, the bot should type if the variable fedex went up or down.
async def bet(ctx, arg1):
def new():
global current
if(arg1=="fedex"):
global fedex
current = fedex
else:
return
new()
stok = current
if(check=="0"):
while(check != "1"):
time.sleep(1.0)
elif(check=="1"):
while(check != "0"):
time.sleep(1.0)
new()
stok2 = current
if(stok2>stok):
await ctx.send("It went up!")
else:
await ctx.send("It went down.")
我不知道用什么替换 time.sleep(1.0)。
【问题讨论】:
标签: python variables time discord.py sleep