You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python给Telegram频道帖子发反应?查Telethon API无果

使用Python给Telegram频道帖子发送反应(Telethon实现)

当然可以,用Telethon的messages.sendReaction方法就能实现,以下是具体步骤和示例:

  • 确保Telethon版本达标:旧版本可能没封装这个方法,先执行更新:

    pip install --upgrade telethon
    
  • 核心代码示例:

    from telethon import TelegramClient
    from telethon.tl.types import ReactionEmoji
    
    # 替换成你的API信息和会话文件名
    api_id = 123456
    api_hash = 'your_api_hash_here'
    session_name = 'my_session'
    
    async def send_post_reaction():
        async with TelegramClient(session_name, api_id, api_hash) as client:
            # 频道标识,可用用户名(如@my_channel)或频道ID
            target_channel = '@my_channel'
            # 帖子ID,从帖子链接(如https://t.me/my_channel/123)里提取
            target_msg_id = 123
            # 要发送的emoji反应
            reaction = ReactionEmoji(emoji='❤️')
            
            await client.send_reaction(target_channel, target_msg_id, reaction)
            print("反应发送成功")
    
    if __name__ == '__main__':
        import asyncio
        asyncio.run(send_post_reaction())
    
  • 参数说明:

    • target_channel:支持频道用户名、数字ID或Telethon实体对象
    • target_msg_id:对应帖子的消息ID,可在客户端右键帖子复制链接获取
    • reaction:除了ReactionEmoji,还能用ReactionCustomEmoji发送自定义贴纸反应(需传入贴纸ID)
  • 注意事项:

    • 你的账号需要是频道管理员/所有者(自己的频道默认满足),拥有发送反应的权限
    • 首次运行客户端需要验证手机号,后续会话文件会保存登录状态,无需重复验证

内容的提问来源于stack exchange,提问作者WA SENDER

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 07:15:42