Пожалуйста, обратите внимание, что пользователь заблокирован
hi, anyone has a script to auto add telegram members of one group to another, also auto subscribe users to a channel?
Последнее редактирование:
from telethon import TelegramClient
from telethon.tl.functions.channels import InviteToChannelRequest, JoinChannelRequest
import asyncio
import random
api_id = 12345678
api_hash = 'your_api_hash_here'
phone_number = '+1234567890'
source_group_username = 'sourcegroup'
destination_group_username = 'targetgroup'
target_channel_username = 'targetchannel'
client = TelegramClient('session_name', api_id, api_hash)
async def main():
await client.start(phone=phone_number)
try:
await client(JoinChannelRequest(source_group_username))
except Exception as e:
print(f"[Предупреждение] Не удалось присоединиться к исходной группе: {e}")
print("Получение участников из исходной группы...")
try:
source_group = await client.get_entity(source_group_username)
participants = await client.get_participants(source_group)
print(f"Получено {len(participants)} участников.")
except Exception as e:
print(f"Ошибка при получении участников: {e}")
return
try:
destination_group = await client.get_entity(destination_group_username)
target_channel = await client.get_entity(target_channel_username)
except Exception as e:
print(f"Ошибка при получении целевых сущностей: {e}")
return
for user in participants:
try:
print(f"Добавление {user.id} в группу {destination_group.title}...")
await client(InviteToChannelRequest(destination_group, [user]))
print(f"Добавление {user.id} в канал {target_channel.title}...")
await client(InviteToChannelRequest(target_channel, [user]))
wait_time = random.randint(5, 10)
print(f"Ожидание {wait_time} секунд перед добавлением следующего участника...")
await asyncio.sleep(wait_time)
except Exception as e:
print(f"Не удалось добавить {user.id}: {e}")
wait_time = random.randint(5, 10)
print(f"Ожидание {wait_time} секунд перед повторной попыткой...")
await asyncio.sleep(wait_time)
if __name__ == '__main__':
with client:
client.loop.run_until_complete(main())