LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.01k stars 1.41k forks source link

UserBannedInChannelError: You’re banned from sending messages in supergroups/channels (caused by InviteToChannelRequest) #3948

Closed Exenex1 closed 2 years ago

Exenex1 commented 2 years ago

Checklist

Thats problem is on all accounts, which was registered more than 7 days ago. Not virtual number. 2 days ago I forgot install PySocks and my proxy didn’t work when I use my script. So now I try to start my script with proxy and have problem

Code that causes the issue

from telethon.sync import TelegramClient

def main():
    client = utils.get_client()

    os.system('clear')
    utils.banner()
    users = database.get_users()
    chats = utils.get_chats(client)
    target_chat = utils.choose_chat(chats)
    all_participants = client.iter_participants(target_chat, aggressive=True)
    chat_users_id = []
    for chat_user in all_participants:
        chat_users_id.append(chat_user.id)

    exc_count = 0

    for user in users:
        if database.is_user_invited(user_id=user.user_id, chat_id=target_chat.id) or user.user_id in chat_users_id:
            continue
        time.sleep(1)
        try:
            print("Adding {}  {}".format(user.user_id, user.username))

            user_to_add = InputUser(user.user_id, user.access_hash)

            client(InviteToChannelRequest(channel=InputChannel(target_chat.id, target_chat.access_hash),
                                          users=[user_to_add]))
            print(gr + "[+] Waiting for 10-30 Second...")
            database.add_invited_user(user.user_id, user.username, target_chat.id)
            time.sleep(random.randrange(10, 30))

Traceback


Traceback (most recent call last):
  File "C:\Users\я\Desktop\Парсер по сообщениям\обмен валют\среда\TGPars (7490) Садык Плеснев\invite.py", line 42, in main
    client(InviteToChannelRequest(channel=InputChannel(target_chat.id, target_chat.access_hash),
  File "C:\Users\я\AppData\Roaming\Python\Python310\site-packages\telethon\sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Users\я\AppData\Roaming\Python\Python310\site-packages\telethon\client\users.py", line 30, in call
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\я\AppData\Roaming\Python\Python310\site-packages\telethon\client\users.py", line 84, in _call
    result = await future
telethon.errors.rpcerrorlist.UserBannedInChannelError: You're banned from sending messages in supergroups/channels (caused by InviteToChannelRequest)
Lonami commented 2 years ago

You are using raw API, which means the results you are getting come directly from Telegram, and Telethon is not changing them in any way (other than adapting some input parameters where needed, all while respecting the intended values). Unfortunately this means it's something Telethon cannot "fix" and it's just the way Telegram's API works.