如何通过在Discord.py中等待用户消息输入来获得tictactoe游戏的用户输入



我在while循环中使用await bot.wait_for。尽管有await bot.wait_for,但代码只是在运行,无限地等待printBoard(ctx, board)

@bot.command()
async def tictactoe(ctx, xo="X"):
await ctx.send(
"Enter your move according to this key till I figure out a better way:nA1tB1tC1tnA2tB2tC2tnA3tB3tC3t"
)
user = xo.upper
board = ttt.initial_state()
gameOver = ttt.terminal(board)
while not gameOver:
await printBoard(ctx, board)
player = ttt.player(board)
if user == player:
await ctx.send(f"Play as {user}:")
def check(msg):
return (
msg.author == ctx.author
and msg.channel == ctx.channel
and msg.content.upper()
in ["A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "C3"]
)
msg = await bot.wait_for("message", check=check, timeout=60.0)
move = h.tttMoves[msg.content.upper()]
print(move)

我希望脚本在await bot.wait_for处暂停,直到它得到用户消息(相当于python在使用input((时如何等待终端输入(。我该如何实现这个结果?

我认为如果你给unlimited timeout,它会等待,直到得到消息

最新更新