【问题标题】:How to send message to Telegram channel in Telethon如何在 Telethon 中向 Telegram 频道发送消息
【发布时间】:2019-04-07 03:08:07
【问题描述】:

在另一个消息事件被调用后,我试图向 Telegram 频道发送消息。我下面的代码使用频道名称作为实体,但它并不总是有效。任何想法我将如何以更好和有效的方式进行。

@client.on(events.NewMessage(chats=channel))
async def my_event_handler(event):
    values = formatter(event.raw_text)
    await client.send_message('destination', template.format(coin=values[0], buy=values[1]))

client.start()
client.run_until_disconnected()

【问题讨论】:

    标签: python telethon


    【解决方案1】:

    这是Documentation
    所以我用用户名“abdx”发送了一条消息,上面写着“Hello python”。

    client = TelegramClient('session_name',
                        api_id,
                        api_hash,
                        )
    client.start()
    destination_user_username='abdx'
    entity=client.get_entity(destination_user_username)
    client.send_message(entity=entity,message="Hello python")
    

    Alihossein shahabi

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 2022-07-17
      • 2019-04-27
      • 2019-11-28
      • 2021-06-11
      • 1970-01-01
      相关资源
      最近更新 更多