我正在使用一个用于twitch的机器人,它跟踪用户在频道中花费的时间。!time You have spent 10 seconds in the stream
。但是,当多个用户使用此命令!time
时,每个用户没有单独的“计数”。例如:
Rustie: !time
Bot: Rustie, you have 20 seconds in the stream.
~1 minute later~
John: !time
Bot: John, you have 1 minute 20 seconds in the stream.
我的当前代码:
usersForTime = []
if "time" in message:
if user in usersForTime:
endTime = time.time() # I already made startTime in the !start command (which starts the time tracker in the first place)
ellapsed = (endTime - startTime)
sendMessage(s, user + ", you have " + "%.2f" % round(ellapsed, 2) + " seconds in the stream.")
else:
sendMessage(s ,"You need to start tracking your time with the !start command.")
您需要存储与特定用户关联的startTime,例如
它使用字典来查找个人的开始时间。你知道吗
要最初存储它(在
!start
):相关问题 更多 >
编程相关推荐