Answer the question
In order to leave comments, you need to log in
I want the bot to replace the photo of the group, but the error AttributeError: 'NoneType' object has no attribute 'photo' appears, what should I change in the code?
I watch a course on creating telegram bots, I take a code from it, I need a person to send a photo, forward it, but at the same time write the /set_photo command, and the photo of the group is replaced, but when I enter it, I get an error, everything works in the teacher
import io
from aiogram import types
from aiogram.dispatcher.filters import Command
from filters import AdminFilter
from loader import dp
@dp.message_handler(Command('set_photo'), AdminFilter())
async def set_photo_groups(message: types.Message):
source_message = message.reply_to_message
photo = source_message.photo[-1]
photo = await photo.download(destination=io.BytesIO())
input_file = types.InputFile(path_or_bytesio=photo)
await message.chat.set_photo(photo=input_file)
Answer the question
In order to leave comments, you need to log in
You need to read about the state machine, or state machine. In aiogram, all this is very well implemented.
So you can describe the process of replacing a photo in a chat.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question