@resresres

Как добавит юзер бота на pyrogram на канал?

Как мне добавить юзер бота на канал я прочел документацию join_chat() но не получается сделать.
from pyrogram import Client, filters
from os import listdir
import os

a=listdir('PH_videos')
PH=[]
for i in a:
    if i.endswith('.mp4'):
            PH.append(i)
           
app = Client("my_account")

with app:
    app.join_chat('https://t.me/redendertestpy')
    num=0
    while True:
        
        app.send_video("me", r"C:\Users\Rasul\Desktop\PH_Poster\PH_videos\\"+PH[num])
        num=num+1
app.run()


Traceback (most recent call last):
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 60, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 147, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: https://t.me/redendertestpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 69, in resolve_peer
int(peer_id)
ValueError: invalid literal for int() with base 10: 'https://t.me/redendertestpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 72, in resolve_peer
return await self.storage.get_peer_by_username(peer_id)
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 158, in get_peer_by_username
raise KeyError(f"Username not found: {username}")
KeyError: 'Username not found: https://t.me/redendertestpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Rasul\Desktop\PH_Poster\PH_poster.py", line 14, in
app.join_chat('https://t.me/redendertestpy')
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\sync.py", line 56, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\chats\join_chat.py", line 68, in join_chat
channel=await self.resolve_peer(chat_id)
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 74, in resolve_peer
await self.send(
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\methods\advanced\send.py", line 77, in send
r = await self.session.send(
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\session\session.py", line 425, in send
return await self._send(data, timeout=timeout)
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\session\session.py", line 395, in _send
RPCError.raise_it(result, type(data))
File "C:\Users\Rasul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyrogram\errors\rpc_error.py", line 78, in raise_it
raise getattr(
pyrogram.errors.exceptions.bad_request_400.UsernameInvalid: [400 USERNAME_INVALID]: The username is invalid (caused by "contacts.ResolveUsername")
  • Вопрос задан
  • 751 просмотр
Пригласить эксперта
Ответы на вопрос 1
@ydooG
Нужно передавать в метод join_chat либо ссылку-приглашение, либо только username чата. А в вашем коде передается просто ссылка на чат.
То есть нужно без https://t.me/
app.join_chat('edendertestpy')
Внимательно просмотрите примеры из документации
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы