Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 读电报组报文_Python_Telegram_Telegram Bot - Fatal编程技术网

Python 读电报组报文

Python 读电报组报文,python,telegram,telegram-bot,Python,Telegram,Telegram Bot,我加入了一个电报组。我想在python代码中阅读这些消息。有没有办法不在该组中添加bot来读取这些消息。。例如,abc是我的用户id。。。在xyz组中添加abc。所以我想在python代码中读取xyz组消息。是的,您可以通过使用名为Telethon的电报API来实现 下面是一个设置TelethonAPI进程的示例。我写这段代码是为了从一个电报组中提取所有新发布的图像。它会让你知道如何开始使用它 import sys import os from telethon import Telegra

我加入了一个电报组。我想在python代码中阅读这些消息。有没有办法不在该组中添加bot来读取这些消息。。例如,abc是我的用户id。。。在xyz组中添加abc。所以我想在python代码中读取xyz组消息。

是的,您可以通过使用名为Telethon的电报API来实现

下面是一个设置TelethonAPI进程的示例。我写这段代码是为了从一个电报组中提取所有新发布的图像。它会让你知道如何开始使用它

import sys
import os

from telethon import TelegramClient
from telethon.tl.functions.messages import GetFullChatRequest
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.tl.functions.channels import GetChannelsRequest
from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.types import PeerUser, PeerChat, PeerChannel
import re
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = 11111  #number
api_hash = 'x'#string
phone = 'x'
client = TelegramClient('session_name', api_id, api_hash,update_workers=1, spawn_read_thread=False)
client.connect()
另外,如果您对我在这个Telethon集成上的所有代码感兴趣,您可以在下面的GitHub链接中找到它


好的,谢谢。任何代码片段都会对我有所帮助。。有点像电报新手如果你觉得我的答案有帮助,请把它标记为答案:)