question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`commands` in `@dp.message_handler` doesn't work with photos

See original GitHub issue

Dispatcher -> message_handler -> command with photo

My setup

  • Operating System: Windows 10
  • Python Version: Python 3.7.3
  • aiogram version: aiogram==2.13

Expected Behavior

Bot should receive and process command with attached photo.

Current Behavior

I can’t send command and photo together.

Description of failure

@dp.message_handler(commands=['mycommand'], content_types=[types.ContentType.TEXT, types.ContentType.PHOTO]) async def command_watermark(message: types.Message): # If you send a command, then the code is reproduced here # If you send a command with a photo, then the code is ignored here.

Help please

Can I do what I want or is it not possible? Please tell me what is the error or another method of solution.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kamikazebrcommented, Jun 20, 2021

@bpqq You tried only like below?

@dp.message_handler(commands=['mycommand'], content_types=[types.ContentType.PHOTO])

And you can try log it to console and check what you got.

After that method command_watermark create new one

@dp.message_handler()
async def print_if_none_is_get(message: types.Message):
    logging.log(f"Message: {message}")

Something like that, maybe you need change your logging to print ou pprint ou ppretty.

2reactions
Olegt0rrcommented, Jun 21, 2021

But when I call the message.text, I get “None”.

You should use caption field instead of text for all content types != ContentType.TEXT.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dispatcher — aiogram 2.23.1 documentation
Decorator for message handler. Examples: Simple commands handler: @dp.message_handler(commands=['start', 'welcome', 'about']) async def cmd_handler(message: ...
Read more >
How to send photos on telegram with python
I am trying to send a photo that I have on my computer to my telegram bot chat when I issue the command...
Read more >
Message Handler - Not Working with Filter.Command & ...
The idea is to accept single or multiple images from the user and get a command i.e. /crop or /removebg and get the...
Read more >
Dispatcher — aiogram 2.2 documentation
This handler works only if state is None (by default). ... PHOTO | ContentType. ... @dp.message_handler(commands=['command']) @dp.message_handler(lambda ...
Read more >
Bring your Telegram Chatbot to the next level
Telegram Bot can work with a Pull or with a Push mechanism (see further Webhooks). ... dp = updater.dispatcher # define command handler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found