'Problem with requesting a phone number in aiogram. python

I have a "Share number" button in my telegram bot. The number can be sent to the bot only in person, and not through a group. If I try to call the "/info" command, an error is displayed in the console, since this command shows buttons and the "Share number" button is shown along with these buttons. The "/info" command works only in a personal message to the bot, and this command also sends the "information" message. How to get around this problem? How to make it so that when the "/info" command is called, "information" is displayed in the group, but the "Share number" button is not displayed?

Handler for command "/info":

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

Part of another file:

b5 = KeyboardButton("Share a number",request_contact=True)
kb_client = ReplyKeyboardMarkup(resize_keyboard=True,one_time_keyboard=True)
kb_client.add(b5)


Solution 1:[1]

@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) has chat and type attribute, you could simply filter private or group

And don't forget to remove reply_markup on the next step

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maksim K.