Как извлечь содержимое сообщения discord.py
Пытаюсь сделать бота, который будет играть в крестики нолики. Не могу получить содержимое сообщения из 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)
Ответы (1 шт):
Автор решения: EVG
→ Ссылка
Содержимое сообщения в discord.py находится в атрибуте content объекта Message.
edited = board.edit(mes.content, 'X')