Sending Telegram messages with Telethon: some entity parameters work, others don't?

前端 未结 1 1934
时光取名叫无心
时光取名叫无心 2021-01-20 03:48

I\'m using Telethon\'s send_message function to send messages to various chats.

Sometimes, the destination is another user (just a regular one on one chat), sometime

相关标签:
1条回答
  • 2021-01-20 04:21

    I suggest reading this section of the document (entities)

    for example, I want to send the message to a user with the username: alix

    client = TelegramClient('session_name',
                        api_id,
                        api_hash,
                        )
    client.start()
    destination_user_username='alix'
    entity=client.get_entity(destination_user_username)
    client.send_message(entity=entity,message="Hi")
    

    or I want to send the message to a channel with username: test_ali3

    client = TelegramClient('session_name',
                        api_id,
                        api_hash
                        )
    client.start()
    
    destination_channel_username='test_ali3'
    entity=client.get_entity(destination_channel_username)
    client.send_message(entity=entity,message="Hi")
    

    or I want to send the message to a group with invite_link: https://t.me/joinchat/Bn4WIhMF1T_ZAF-yM6WbHw

    client = TelegramClient('session_name',
                        api_id,
                        api_hash
                        )
    client.start()
    destination_group_invite_link='https://t.me/joinchat/Bn4WIhMF1T_ZAF-yM6WbHw'
    entity=client.get_entity(destination_group_invite_link)
    client.send_message(entity=entity,message="Hi")
    

    I hope to be useful to you.

    0 讨论(0)
提交回复
热议问题