1
# keyboard
share_keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
share_button = types.KeyboardButton(text="Share", request_contact=True)
share_keyboard.add(share_button)


@dp.message_handler(ChatTypeFilter(chat_type=types.ChatType.PRIVATE))
async def understand_message_handler(message: types.message):

if message.text == "Register" and not await check_user(message.from_user.id):
    await message.answer("Enter phone number:",
                         reply_markup=share_keyboard)
    await Registration.registration_number.set()

@dp.message_handler(state=Registration.registration_number)
async def input_number(message: types.Message, state: FSMContext):
await state.finish()
telephone = message.contact.phone_number
connection = await get_connection()
sql = f"INSERT INTO users(id, number) VALUES ({message.from_user.id}, {telephone})"
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()


# ERROR
'NoneType' object has no attribute 'phone_number'

I use AIOgram and this doesn't work, but with telebot it's works. Tell me please how i can get number im AIOgram?

Frank Delan
  • 13
  • 1
  • 5

1 Answers1

3

By default message handler accepts only text messages - need to change this behavior by adding filter content_types=types.ContentType.CONTACT

hoosnick
  • 136
  • 4