J
J
JonesJ2022-01-15 14:44:46
Python
JonesJ, 2022-01-15 14:44:46

How to make the command work only in aiogram?

How to make the command work only in PM?
@dp.message_handler(content_types=['photo'])

A photo is attached here. And then the bot sends the result.
In a conversation for every photo, it will infuriate

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zagir Majidov, 2022-01-15
@JonesJ

@dp.message_handler(content_types=['photo'])
async def cmd(message):
    if message.chat.type == "private":
        # действие
   else:
      await message.reply("Пользуйтесь ботом в личных сообщениях!")

R
Renat Ataev, 2022-01-16
@fanepka

You can check by chat ID. If the user ID matches the chat ID, then this is a PM

async def echo(message):
    if message.from_user.id == message.chat.id:
        #что-то
    else:
       #что-то

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question