我正在尝试制作一个可以玩井字游戏的机器人。无法从中获取消息内容mes。例如:
@bot.event
async def on_message(mes):
print(int(mes)) # Вызывает ошибку
await bot.process_commands(mes)
完整游戏代码:
@bot.command()
async def play(ctx):
board = Board()
bot_turn = 'O'
game_bot = Bot(True, 'O')
await ctx.send(board)
await ctx.send('[X]: Enter cell number')
@bot.event
async def on_message(mes):
print(mes)
edited = board.edit(mes, 'X') # Здесь (на месте mes) должно быть содержимое сообщения игрока
await ctx.send(board)
if edited:
while True:
cell = game_bot.get_cell(board.get_board(), board.get_void())
bot_edited = board.edit(cell, bot_turn)
if bot_edited:
break
winner = board.is_win()
if winner != False:
if winner == 'O':
statistic['bot win'] += 1
elif winner == 'X':
statistic['player win'] += 1
statistic['total games'] += 1
save_stats(statistic)
await ctx.send(f'[^^]: winner is {winner}')
await bot.process_commands(mes)
if board.is_fill():
statistic['draw'] += 1
statistic['total games'] += 1
save_stats(statistic)
await ctx.send('[^^]: Draw')
await bot.process_commands(mes)
discord.py 中消息的内容在 Message 对象的 content 属性中。
edited = board.edit(mes.content, 'X')