[/LEFT] from pyrogram import Client # Создаём клиент app = Client("client", api_id=12345, api_hash="0123456789abcdef0123456789abcdef") app.start() # Получаем ID чатов chat_ids = [] members = app.get_chat_members(chat_id="@your_bot_username") #введите юзернейм бота for member in members: chat = member.chat if chat.chat_type in ["group", "supergroup", "channel"]: chat_ids.append(chat.id) # Отправка сообщений в каждом чате message_text = "message" for chat_id in chat_ids: try: app.send_message(chat_id, message_text) except Exception as e: print(f"Ошибка при отправке сообщения в чат {chat_id}: {e}") # Закрываем соединение с API Telegram app.stop() [LEFT] Python [/LEFT] from pyrogram import Client # Создаём клиент app = Client("client", api_id=12345, api_hash="0123456789abcdef0123456789abcdef") app.start() # Получаем ID чатов chat_ids = [] members = app.get_chat_members(chat_id="@your_bot_username") #введите юзернейм бота for member in members: chat = member.chat if chat.chat_type in ["group", "supergroup", "channel"]: chat_ids.append(chat.id) # Отправка сообщений в каждом чате message_text = "message" for chat_id in chat_ids: try: app.send_message(chat_id, message_text) except Exception as e: print(f"Ошибка при отправке сообщения в чат {chat_id}: {e}") # Закрываем соединение с API Telegram app.stop() [LEFT] Мб кому надо. На коленке буквально, не гнобить
Роснефть, не понял что именно нужно вписывать в юзернейм бота, выдает ошибку raise getattr( pyrogram.errors.exceptions.bad_request_400.ChannelInvalid: Telegram says: [400 CHANNEL_INVALID] - The channel parameter is invalid (caused by "channels.GetParticipants")
Можешь подсказать, как сделать просто выгрузку в файл списках всех польхователей канала? import pyrogram api_id = api_hash = '' group_id = - # Create a Pyrogram client client = pyrogram.Client('my_session', api_id=api_id, api_hash=api_hash) # Start the client client.start() # Get a list of all the users in the group all_users = [] members = client.get_chat_members(group_id) for member in members: all_users.append(member.user) # Upload the list of users to a text file with open('users.txt', 'w') as f: for user in all_users: f.write(user.username) # Stop the client client.stop() Пробовал так, но не выходит
Утя, Трай это, с пропоя чекал че там, если что завтра пересмотрю import pyrogram api_id = api_hash = '' group_id = - # Create a Pyrogram client with pyrogram.Client('my_session', api_id=api_id, api_hash=api_hash) as client: # Start the client client.start() # Get a list of all the users in the group all_users = [] members = client.iter_chat_members(group_id) for member in members: all_users.append(member.user) # Upload the list of users to a text file with open('users.txt', 'w') as f: for user in all_users: f.write(user.username + "\n") # Stop the client client.stop() Python import pyrogram api_id = api_hash = '' group_id = - # Create a Pyrogram client with pyrogram.Client('my_session', api_id=api_id, api_hash=api_hash) as client: # Start the client client.start() # Get a list of all the users in the group all_users = [] members = client.iter_chat_members(group_id) for member in members: all_users.append(member.user) # Upload the list of users to a text file with open('users.txt', 'w') as f: for user in all_users: f.write(user.username + "\n") # Stop the client client.stop()