So I am using Python 3 to create a script with Telegram API but have come across a pickle.
Essentially I want anything I post to one channel to automatically be posted to a list of other channels.
As there are a lot of channels I am pretty sure I have split it over multiple lines, keeping the variables aligned with the first delimiter as per PEP8 code layout advice. However, for some reason, the code only posts content to the first line of channels in the list and not the others.
Right now my code is:
from telethon import TelegramClient, events
api_id = 9969279 #API_ID
api_hash = 'd5fa4ca47bcdb6f5bda7271f30e607e9' #API_HASH
channel = [-1001612029593] #MAIN_CHANNEL_ID
to_channel = [-1001408569373,-1001450011693,-1001589562089,-1001324581893,-1001486742214,-1001262799053,-1001577547504,-1001751417089,
-1001714682472,-1001173439993,-1001564319953,-1001458872203,-1001580609047,-1001454607304,-1001412291633,-1001307551599,
-1001472656059,-1001577461465,-1001577461465,-1001438912928,-1001166100393,-1001226585647,-1001662052611,-1001412291633,
-1001213093519,-1001543013350,-1001599148038,-1001250770087,-1001489822613,-1001586463068,-1001173726857,-1001425575134,
-1001549263406,-1001566043627,-1001605175905,-1001229590696,-1001442156928] #OTHER_CHANNELS
client = TelegramClient('TGBot', api_id, api_hash)
@client.on(events.NewMessage(chats=channel))
async def my_event_handler(event):
if event.message:
for channelx in to_channel:
await client.send_message(channelx, event.message)
client.start()
client.run_until_disconnected()
I'm wondering as to whether the lines are too long - other than that I can't think of why it won't post all channels?
EDIT: When running the script I get the following notes on my CMD
Traceback (most recent call last):
File "C:\Users\mimif\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\updates.py", line 451, in _dispatch_update
await callback(event)
File "C:\Users\mimif\OneDrive\Desktop\python\main.py", line 18, in my_event_handler
await client.send_message(channelx, event.message)
File "C:\Users\mimif\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\messages.py", line 825, in send_message
return await self.send_file(
File "C:\Users\mimif\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\uploads.py", line 412, in send_file
return self._get_response_message(request, await self(request), entity)
File "C:\Users\mimif\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 30, in __call__
return await self._call(self._sender, request, ordered=ordered)
File "C:\Users\mimif\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 84, in _call
result = await future
telethon.errors.rpcerrorlist.ChannelPrivateError: The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it (caused by SendMediaRequest)```