在 aiogram 中请求 phone 数字时出现问题。 python

Problem with requesting a phone number in aiogram. python

我的电报机器人中有一个“分享号码”按钮。该号码只能亲自发送给机器人,不能通过群组发送。如果我尝试调用“/info”命令,控制台中会显示错误,因为此命令显示按钮并且“共享号码”按钮与这些按钮一起显示。 “/info”命令仅在给 bot 的个人消息中起作用,并且此命令还会发送“information”消息。如何解决这个问题?如何使调用“/info”命令时,群里显示“信息”,但不显示“分享号”按钮?

命令“/info”的处理程序:

asyns def command_botinfo(message: types.Message):
    await message.reply("information ",reply_markup=kb_client)

另一个文件的一部分:

b5 = KeyboardButton("Share a number",request_contact=True)
kb_client = ReplyKeyboardMarkup(resize_keyboard=True,one_time_keyboard=True)
kb_client.add(b5)
@dp.message_handler(commands=['info'])
async def command_botinfo(message: types.Message):
    if message.chat.type == 'private':
        await message.reply("information ", reply_markup=kb_client)
    else:
        await message.reply("information ")

Aiogram message (types:Message)有chat和type属性,你可以直接过滤privategroup

并且不要忘记在下一步中删除 reply_markup