How to change single target entity into list using Telethon module in Python

Question:

I’m trying to write a script that can send a message to Telegram groups. I can only manage to send to one group at the moment, and when I try to add a list, it doesn’t work. Here is the code that I have so far, and the entity I want to create a list of is the channel IDs

from telethon import TelegramClient
from telethon.tl.types import InputPeerChannel
from telethon.tl import types, functions
from telethon.tl.functions.messages import SendMessageRequest

api_id = xxxxxxxx
api_hash = 'xxxxxxx'
client = TelegramClient('user', api_id, api_hash).start()
channel = InputPeerChannel = -123456


async def main():
    await client.send_file(channel, 'imgurl.jpg', caption="It's me!")



with client:
    client.loop.run_until_complete(main())
Asked By: SMariePython

||

Answers:

Standard rule: if you have list then use for-loop.

InputPeerChannel = [-123456]

async def main():
    for channel in InputPeerChannel:
        await client.send_file(channel, 'imgurl.jpg', caption="It's me!")
Answered By: furas
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.