Ошибка при нажатии кнопки Telegram Bot
При нажатии кнопки Addition, которая генерирует пример с арифметическим действием сложение пользователю, выходит вот такая ошибка
TypeError: math_operation() missing 1 required positional argument: 'args'
А вот сам код от бота
import telebot
bot = 'token'
@bot.message_handler(commands=['game'])
def user_message(message):
if message.chat.type == 'private':
if message.text == '/game':
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=5)
addition = types.KeyboardButton('➕ Addition')
markup.add(addition)
bot.send_message(message.chat.id, 'Welcome!', reply_markup=markup)
elif message.text == '➕ Addition':
addition1 = (int(random.randint(1, 10)))
addition2 = (int(random.randint(1, 10)))
answer = addition1 + addition2
args = (answer, )
msg = bot.send_message(message.chat.id, f'Solve the example:\n{int(addition1)} + {int(addition2)}')
bot.register_next_step_handler(msg, math_operation, args=args)
@bot.message_handler(content_types=['text'])
def math_operation(message, args):
answer = args[0]
if int(message.text) == int(answer):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
buttons = [
types.KeyboardButton('? Solve the example again'),
types.KeyboardButton('? Back')
]
markup.row(*buttons)
bot.send_message(message.chat.id, f'The example is solved! ?', reply_markup=markup)
elif not int(message.text) == int(answer):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
buttons = [
types.KeyboardButton('? Solve the example again'),
types.KeyboardButton('? Back')
]
markup.row(*buttons)
bot.send_message(message.chat.id, f'The example is unresolved! ❌', reply_markup=markup)
if __name__ == '__main__':
bot.infinity_polling()
Ответы (1 шт):
Автор решения: oleksandrigo
→ Ссылка
Сделай так
bot.register_next_step_handler(msg, math_operation, args)