Решил написать бота для фото-батлов, а при запуске батла не активируеться возможность отсылать фото на проверку, что делать? import logging import asyncio from aiogram import Bot, Dispatcher, types, Router, F from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InputMediaPhoto from aiogram.filters import Command from aiogram.types import Message, CallbackQuery TOKEN = "YOUR_BOT_TOKEN" ADMIN_ID = YOUR_ADMIN_ID CHANNEL_ID = "@your_channel_id" bot = Bot(token=TOKEN) dp = Dispatcher() router = Router() logging.basicConfig(level=logging.INFO) total_photos = 0 interval = 0 approved_photos = [] battles = {} round_number = 1 setting_photos = True photo_collection_started = False @router.message(Command("start")) async def start(message: Message): global setting_photos, total_photos, interval, approved_photos, battles, round_number, photo_collection_started if message.from_user.id == ADMIN_ID: setting_photos = True photo_collection_started = False total_photos = 0 interval = 0 approved_photos.clear() battles.clear() round_number = 1 await message.answer("Привіт, адміне! Введіть загальну кількість фото для турніру:") else: await message.answer("Привіт! Дочекайтеся оголошення про набір фото.") @router.message(F.text.isdigit()) async def process_number(message: Message): global total_photos, interval, setting_photos, photo_collection_started if setting_photos: total_photos = int(message.text) if total_photos < 2 or total_photos % 2 != 0: await message.answer("Кількість фото має бути парною і не меншою за 2. Введіть ще раз:") else: await message.answer(f"Прийнято! Турнір буде з {total_photos} фото. Тепер введіть інтервал між раундами (у хвилинах):") setting_photos = False else: interval = int(message.text) * 60 rounds = total_photos // 2 photo_collection_started = True await bot.send_message( CHANNEL_ID, f" Набір фото для фотобатлу!\n\n" f" Буде проведено {rounds} раундів.\n" f"✅ Приймаємо {total_photos} фото.\n" f" Надсилайте фото в бот, щоб взяти участь!" ) await message.answer("Оголошення зроблено! Чекаємо заявки.") @router.message(F.content_type == "photo") async def handle_photo(message: Message): global approved_photos, photo_collection_started if not photo_collection_started: await message.answer("Набір фотографій ще не оголошено. Зачекайте на оголошення адміністратора.") return if len(approved_photos) >= total_photos: await message.answer("Набір фото завершено!") return approved_photos.append(message.photo[-1].file_id) await message.answer("✅ Ваше фото прийнято!") if len(approved_photos) == total_photos: await start_battles() async def start_battles(): global round_number while len(approved_photos) >= 2: await asyncio.sleep(interval) photo1 = approved_photos.pop(0) photo2 = approved_photos.pop(0) buttons = [ InlineKeyboardButton(text=f" 1 (0)", callback_data="vote_1"), InlineKeyboardButton(text=f" 2 (0)", callback_data="vote_2") ] keyboard = InlineKeyboardMarkup(inline_keyboard=[buttons]) media = [ InputMediaPhoto(media=photo1), InputMediaPhoto(media=photo2, caption=f" {round_number} РАУНД\n\n1- 2-") ] message_group = await bot.send_media_group(CHANNEL_ID, media) msg = await bot.send_message(CHANNEL_ID, "Голосуйте за учасників!", reply_markup=keyboard) battles[msg.message_id] = { "photos": [photo1, photo2], "votes": [0, 0], "message_group_ids": [m.message_id for m in message_group] } round_number += 1 await asyncio.sleep(interval) await finish_battle() @router.callback_query(lambda call: call.data.startswith("vote_")) async def handle_vote(call: CallbackQuery): message_id = call.message.message_id vote_index = int(call.data.split("_")[1]) - 1 if message_id not in battles: await call.answer("Цей батл не знайдено.") return battles[message_id]["votes"][vote_index] += 1 buttons = [ InlineKeyboardButton(text=f" 1 ({battles[message_id]['votes'][0]})", callback_data="vote_1"), InlineKeyboardButton(text=f" 2 ({battles[message_id]['votes'][1]})", callback_data="vote_2") ] keyboard = InlineKeyboardMarkup(inline_keyboard=[buttons]) await call.message.edit_reply_markup(reply_markup=keyboard) await call.answer("Ваш голос зараховано!") async def finish_battle(): winners = [] for message_id, battle in battles.items(): max_votes = max(battle["votes"]) winning_index = battle["votes"].index(max_votes) winners.append(battle["photos"][winning_index]) for m_id in battle["message_group_ids"]: await bot.delete_message(CHANNEL_ID, m_id) await bot.delete_message(CHANNEL_ID, message_id) if winners: media = [InputMediaPhoto(media=photo) for photo in winners] media[-1].caption = " ПЕРЕМОЖЦІ ФОТОБАТЛУ!" await bot.send_media_group(CHANNEL_ID, media) await bot.send_message(CHANNEL_ID, "Дякуємо всім за участь! ") battles.clear() async def main(): dp.include_router(router) await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot) if __name__ == "__main__": asyncio.run(main()) Python import logging import asyncio from aiogram import Bot, Dispatcher, types, Router, F from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InputMediaPhoto from aiogram.filters import Command from aiogram.types import Message, CallbackQuery TOKEN = "YOUR_BOT_TOKEN" ADMIN_ID = YOUR_ADMIN_ID CHANNEL_ID = "@your_channel_id" bot = Bot(token=TOKEN) dp = Dispatcher() router = Router() logging.basicConfig(level=logging.INFO) total_photos = 0 interval = 0 approved_photos = [] battles = {} round_number = 1 setting_photos = True photo_collection_started = False @router.message(Command("start")) async def start(message: Message): global setting_photos, total_photos, interval, approved_photos, battles, round_number, photo_collection_started if message.from_user.id == ADMIN_ID: setting_photos = True photo_collection_started = False total_photos = 0 interval = 0 approved_photos.clear() battles.clear() round_number = 1 await message.answer("Привіт, адміне! Введіть загальну кількість фото для турніру:") else: await message.answer("Привіт! Дочекайтеся оголошення про набір фото.") @router.message(F.text.isdigit()) async def process_number(message: Message): global total_photos, interval, setting_photos, photo_collection_started if setting_photos: total_photos = int(message.text) if total_photos < 2 or total_photos % 2 != 0: await message.answer("Кількість фото має бути парною і не меншою за 2. Введіть ще раз:") else: await message.answer(f"Прийнято! Турнір буде з {total_photos} фото. Тепер введіть інтервал між раундами (у хвилинах):") setting_photos = False else: interval = int(message.text) * 60 rounds = total_photos // 2 photo_collection_started = True await bot.send_message( CHANNEL_ID, f" Набір фото для фотобатлу!\n\n" f" Буде проведено {rounds} раундів.\n" f"✅ Приймаємо {total_photos} фото.\n" f" Надсилайте фото в бот, щоб взяти участь!" ) await message.answer("Оголошення зроблено! Чекаємо заявки.") @router.message(F.content_type == "photo") async def handle_photo(message: Message): global approved_photos, photo_collection_started if not photo_collection_started: await message.answer("Набір фотографій ще не оголошено. Зачекайте на оголошення адміністратора.") return if len(approved_photos) >= total_photos: await message.answer("Набір фото завершено!") return approved_photos.append(message.photo[-1].file_id) await message.answer("✅ Ваше фото прийнято!") if len(approved_photos) == total_photos: await start_battles() async def start_battles(): global round_number while len(approved_photos) >= 2: await asyncio.sleep(interval) photo1 = approved_photos.pop(0) photo2 = approved_photos.pop(0) buttons = [ InlineKeyboardButton(text=f" 1 (0)", callback_data="vote_1"), InlineKeyboardButton(text=f" 2 (0)", callback_data="vote_2") ] keyboard = InlineKeyboardMarkup(inline_keyboard=[buttons]) media = [ InputMediaPhoto(media=photo1), InputMediaPhoto(media=photo2, caption=f" {round_number} РАУНД\n\n1- 2-") ] message_group = await bot.send_media_group(CHANNEL_ID, media) msg = await bot.send_message(CHANNEL_ID, "Голосуйте за учасників!", reply_markup=keyboard) battles[msg.message_id] = { "photos": [photo1, photo2], "votes": [0, 0], "message_group_ids": [m.message_id for m in message_group] } round_number += 1 await asyncio.sleep(interval) await finish_battle() @router.callback_query(lambda call: call.data.startswith("vote_")) async def handle_vote(call: CallbackQuery): message_id = call.message.message_id vote_index = int(call.data.split("_")[1]) - 1 if message_id not in battles: await call.answer("Цей батл не знайдено.") return battles[message_id]["votes"][vote_index] += 1 buttons = [ InlineKeyboardButton(text=f" 1 ({battles[message_id]['votes'][0]})", callback_data="vote_1"), InlineKeyboardButton(text=f" 2 ({battles[message_id]['votes'][1]})", callback_data="vote_2") ] keyboard = InlineKeyboardMarkup(inline_keyboard=[buttons]) await call.message.edit_reply_markup(reply_markup=keyboard) await call.answer("Ваш голос зараховано!") async def finish_battle(): winners = [] for message_id, battle in battles.items(): max_votes = max(battle["votes"]) winning_index = battle["votes"].index(max_votes) winners.append(battle["photos"][winning_index]) for m_id in battle["message_group_ids"]: await bot.delete_message(CHANNEL_ID, m_id) await bot.delete_message(CHANNEL_ID, message_id) if winners: media = [InputMediaPhoto(media=photo) for photo in winners] media[-1].caption = " ПЕРЕМОЖЦІ ФОТОБАТЛУ!" await bot.send_media_group(CHANNEL_ID, media) await bot.send_message(CHANNEL_ID, "Дякуємо всім за участь! ") battles.clear() async def main(): dp.include_router(router) await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot) if __name__ == "__main__": asyncio.run(main())