【问题标题】:Send message to telegram channel with telethon and get mobile notification使用 Telethon 向电报频道发送消息并获取移动通知
【发布时间】:2021-07-12 17:43:26
【问题描述】:

我想使用 Telethon 向我自己的私人频道发送消息,并在 python 脚本发布消息时接收移动推送通知。使用下面的代码,我可以发送消息,但我没有收到任何移动推送通知。我已打开移动应用程序中的所有通知设置。我一直在谷歌搜索“电视推送通知”,但没有任何运气。

from telethon import TelegramClient

api_id = 'api_id'
api_hash = 'api_hash'
username = 'username'
channel_invite_link = 'channel invite link'


async def func():
    entity = await client.get_entity(channel_invite_link)
    await client.send_message(entity=entity, message="Hi")


with TelegramClient(username, api_id, api_hash) as client:
    client.loop.run_until_complete(func())

【问题讨论】:

  • 您不会收到推送通知,因为您是发送消息的人。使用另一个帐户或机器人发送它。如果您已经在这样做并且它不起作用,那么您可能无法从自己的频道获得通知。我自己从未尝试过。
  • 假设它是您的频道,您可以创建一个机器人(通过@BotFather),将其作为管理员添加到您的频道,然后使用该机器人发送消息。这样您应该会收到通知,因为就像 nitan 所说,如果您是发送消息的人,您不会收到通知。
  • @Lonami:我按照你的提示,用 BotFather 创建了一个机器人,我用它来发送消息。我现在按预期收到推送通知。

标签: python telegram telethon


【解决方案1】:

只需使用silent 参数,即:

await client.send_message(entity=entity, message="Hi", silent=False)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2021-04-11
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多