Answer the question
In order to leave comments, you need to log in
How to pass message.text to a variable?
The TextMSG
variable must contain the user's message.
But it gives an error AttributeError: 'CallbackQuery' object has no attribute 'text' .
How can you do?
@dp.callback_query_handler(text="TT1")
async def TT1(message: types.Message):
await bot.delete_message(message.from_user.id, message.message.message_id)
await bot.send_message(message.from_user.id, f'<b>Введите промо:</b>', reply_markup=nav.FF2)
TextMSG = message.text.strip()
if TextMSG == 'Dxx11qeq41':
await bot.delete_message(message.from_user.id, message.message.message_id)
await bot.send_message(message.from_user.id, f'+', reply_markup=nav.FF2)
else:
await bot.delete_message(message.from_user.id, message.message.message_id)
await bot.send_message(message.from_user.id, f'-', reply_markup=nav.FF2)
Answer the question
In order to leave comments, you need to log in
your input function must take a value not of the Message type, but of the CallbackQuery type.
In the end it should be something like this:
@dp.callback_query_handler(text="TT1")
async def TT1(call: types.CallbackQuery):
print(call.message.text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question