bot = Bot(token=TOKEN)
dp = Dispatcher()
chat_ids = []
async def check_if_bot_is_admin(chat_id):
member = await bot.get_chat_member(chat_id, bot.id)
resp = member.status
return resp
@dp.message(F.photo)
async def handle_photo(message: types.Message):
for group_id in chat_ids:
is_admin = await check_if_bot_is_admin(group_id)
if message.chat.type == 'private' and is_admin:
await message.copy_to(chat_id=group_id)
async def main():
await dp.start_polling(bot)
如您所见,运行此代码后,当您将图像作为私人消息发送给机器人时,机器人开始发送到
chat_ids
列表中的组(并且在它之前检查它是否有管理员) )。但现在我需要手动填写这个chat_ids
列表。我不知道如何在将机器人添加到该组后自动附加该组的任何 id。
我制作这个机器人的目标是确保在将任何图像作为私人消息发送给机器人后,它将图像发送到它拥有管理员的所有组。
您必须使用 ChatMemberHandler 来识别您的机器人添加到的位置,然后附加该 chat_id`。