from telethon import TelegramClient, connection, utils, types
import asyncio
import socks
import random
import time
from telethon.tl.types import InputPeerChat
import nest_asyncio
nest_asyncio.apply()
B = []
A = ["1", "2", "3", "4"]
b = int(len(A) - 1)
api_id =
api_hash =
async def groups():
async with TelegramClient('3', api_id, api_hash, proxy=(socks.SOCKS5, '', , True, '', '')) as client:
async for dialog in client.iter_dialogs():
if dialog.is_group:
chat = await client.get_input_entity(dialog.id)
print('{:>14}: {}'.format(dialog.id, dialog.title))
print(chat)
B.append(chat)
return B
asyncio.run(groups())
async def main():
for i in B:
u = len(B) - 1
for i in range(u):
u -= 1
x = B[u]
print(x)
print(u)
async with TelegramClient('3', api_id, api_hash, proxy=(socks.SOCKS5, '', 64275, True, '', '')) as client:
await client.send_message(x, message=str(A[random.randint(0, b)]))
time.sleep(20)
asyncio.run(main())
How does the entity looks like? InputPeerChat(chat_id=1234567)?. Tell me how to make my code work plz.
This is repost of an old question(nobody helped)
I tried to use ids, not the entities. Didnt work either. Access hash is not required for chats(groups). apis are correct as well as proxy. Explain plz.