Home > Software design >  How to change single target entity into list using Telethon module in Python
How to change single target entity into list using Telethon module in Python

Time:09-17

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

CodePudding user response:

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!")
  • Related