首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如果用户已经与AIOgram共享,如何获取电话号码

如果用户已经与AIOgram共享,如何获取电话号码
EN

Stack Overflow用户
提问于 2022-04-20 18:05:06
回答 1查看 1K关注 0票数 1
代码语言:javascript
运行
复制
# 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'

我使用AIOgram,这不起作用,但是有了telebot,它就能工作了。请告诉我我怎样才能得到im AIOgram号码?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-20 23:25:29

默认情况下,消息处理程序只接受文本消息-需要通过添加筛选器content_types=types.ContentType.CONTACT来更改此行为。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71944251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档