• XSS.stack #1 – первый литературный журнал от юзеров форума

need help with telethon

dmitriblovv

(L3) cache
Забанен
Регистрация
27.03.2024
Сообщения
195
Реакции
14
Гарант сделки
2
Пожалуйста, обратите внимание, что пользователь заблокирован
hi, anyone has a script to auto add telegram members of one group to another, also auto subscribe users to a channel?
 
Последнее редактирование:
Python:
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())

requirements:
telethon==1.34.0
python3.8+

source_group_username = 'sourcegroup' — откуда брать участников
destination_group_username = 'targetgroup' — куда добавлять участников
target_channel_username = 'targetchannel' — канал, куда подписывать участников (если нужно)

с мейна лучше не юзать, кидать админку на твинк
сделал генерацию для задержки вместо фикс времени для бан евейда
!!если у кого-то время горит и считает нейронку-модера в тг юзлес:

wait_time = random.randint(5, 10) - удаляем
меняем await asyncio.sleep(wait_time) на await asyncio.sleep(5) - в скобочках время делея
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх