I was writing a Telegram bot noticed that it doesn't respond to photos. This echo bot should copy every message (other than /start
) and sendit back using message.send_copy(message.from_id)
. It works on simple text messages, but if I send a photo to the bot, it doesn't do anything. Here is the code:
import config
from aiogram import Bot, Dispatcher, executor, types
bot = Bot(config.TOKEN, parse_mode="HTML")
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start_cmd(message: types.Message):
await message.answer('Hello!')
@dp.message_handler()
async def echo(message: types.Message):
await message.send_copy(message.from_id)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
I tried to use content_types='*'
like this:
@dp.message_handler(content_types='*')
async def echo(message: types.Message):
await message.send_copy(message.from_id)
but this did not work.
Thanks Kolay.Ne I found what I was searching. I should modify my code like this:
import config
from aiogram import Bot, Dispatcher, executor, types
from aiogram.enums.content_type import ContentType
bot = Bot(config.TOKEN, parse_mode="HTML")
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start_cmd(message: types.Message):
await message.answer('Hello!')
@dp.message_handler(content_types=ContentType.ANY) # or 'any'
async def echo(message: types.Message):
await message.send_copy(message.from_id)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
replacing content_types='*'
with ContentType.ANY
.