Я пишу бота в телеграмме. По нажатию на инлайн кнопку он должен присылать фитографии(функция "exemples"). К ним прикрепляется другая инлайн кнопка и при её нажатии все присланные фотографии должны удаляться, но по какой то причине возникает ошибка:
aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't change private
aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't change private
chat photo
функция называется "clouse_call"
Код:
import asyncio
import os
from aiogram import Router, types, Bot, F
from aiogram.filters import CommandStart, Command
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InputFile
from aiogram.methods import GetChat
#tracemalloc.start()
eow_rt = Router()
bot = Bot(token=os.getenv('TOKEN'))
ikb1 = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Портреты", callback_data='портретid')],
[InlineKeyboardButton(text="Животные", callback_data='животныеid')],
[InlineKeyboardButton(text="Пейзажи/натюрморты", callback_data='пейзажid')],
[InlineKeyboardButton(text="Техника (мотоб авто)", callback_data='техникаid')],
])
ikb2 = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="На холсте маслом", callback_data='масломid')],
[InlineKeyboardButton(text="На бумаге акварелью", callback_data='акварельid')],
[InlineKeyboardButton(text="На бумаге карандашом/углём/тушью", callback_data='карандашid')],
[InlineKeyboardButton(text="На одежде", callback_data='одеждаid')],
[InlineKeyboardButton(text="На стене", callback_data='стенаid')],
[InlineKeyboardButton(text="На деревянных изделиях", callback_data='росписьid')],
])
ikb3 = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Закрыть", callback_data="clouse")]
])
idMess = 0
@eow_rt.callback_query(F.data == 'examples')
async def exemples(call: types.callback_query):
await call.message.answer("По сюжетам:", reply_markup=ikb1)
await call.message.answer("По технике исполнения:", reply_markup=ikb2)
await call.answer()
@eow_rt.callback_query(F.data.in_({"портретid", "животныеid", "пейзажid", "техникаid", "масломid", "акварельid","карандашid", "одеждаid", "стенаid", "росписьid"}))
async def exemples2(call: types.callback_query):
global idMess
calltxt = call.data
with open(f'xxx\\photo\\{calltxt}', 'r') as file:
text_id = file.read()
fileID = text_id.split(',')
for i in fileID:
Mess = await bot.send_photo(chat_id=call.message.chat.id, photo=i, reply_markup=ikb3)
idMess += 1
print(idMess)
@eow_rt.callback_query(F.data == 'clouse')
async def clouse_call(call: types.CallbackQuery):
global idMess
#copy_idMess = idMess.copy()
chat_id = call.message.chat.id
for i in range(idMess):
a = await bot.delete_chat_photo(chat_id=chat_id)
print(a)
idMess = 0
вот полностью вся ошибка(если это каму-то нужно):
Cause exception while process update id=367510245 by bot id=7409384343
TelegramBadRequest: Telegram server says - Bad Request: can't change private chat photo
Traceback (most recent call last):
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\middlewares\error.py", line 25, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\middlewares\user_context.py", line 49, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\fsm\middleware.py", line 42, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 276, in _listen_update
return await self.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 170, in _propagate_event
response = await router.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\router.py",
line 162, in _propagate_event
response = await observer.trigger(event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "c:\vs code projects\anna_bot\xxx\project\exemples_of_works.py", line 66, in clouse_call
a = await bot.delete_chat_photo(chat_id=chat_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\client\bot.py", line 1125, in delete_chat_photo
return await self(call, request_timeout=request_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\client\bot.py", line 485, in __call__
return await self.session(self, method, timeout=request_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\client\session\base.py", line 254, in __call__
return cast(TelegramType, await middleware(bot, method))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\client\session\aiohttp.py", line 189, in make_request
response = self.check_response(
^^^^^^^^^^^^^^^^^^^^
File "C:\vs code projects\anna_bot\anna_venv\Lib\site-packages\aiogram\client\session\base.py", line 120, in check_response
raise TelegramBadRequest(method=method, message=description)
aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't change private
chat photo