R
R
resresres2021-01-08 19:55:04
Python
resresres, 2021-01-08 19:55:04

How can a user add a pyrogram bot to a channel?

How do I add a bot user to a channel, I read the join_chat() documentation, but I can't do it.

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")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
ydooG, 2021-11-17
@ydooG

You need to pass either an invitation link or just the username of the chat to the join_chat method. And in your code, just a link to the chat is passed.
That is, you need without https://t.me/ Carefully review the examples from the documentation
app.join_chat('edendertestpy')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question