如何从我的私人电报频道中读取消息?
我正在尝试从我的私人电报频道中阅读消息。我使用了以下代码。我在私有情况下阅读该消息时面临问题,但是如果我将渠道更改为公众,则该代码正常工作。但是我希望该频道私密,有什么解决方案吗?
import configparser
import json
import re
from telethon.errors import SessionPasswordNeededError
from telethon import TelegramClient, events, sync
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon.tl.types import (PeerChannel)
api_id = *******
api_hash = ******
# Here you define the target channel that you want to listen to:
user_input_channel = 'https://t.me/<channel_id>'
client = TelegramClient('name', api_id, api_hash)
# Listen to messages from target Channel
@client.on(events.NewMessage(chats=user_input_channel))
async def newMessageListner(event):
# Get message text
newMessage = event.message.message
print(newMessage)
with client:
client.run_until_disconnected()
在私人中使用频道时,我会收到此错误消息
Cannot find any entity corresponding to "https://t.me/<channel_id>"
注意: 通道ID被删除
I am trying to read messages from my private telegram channel. I used the following code. I am facing a problem reading the message while it is in private but if I change the channel to the public this code is working fine. But I want the channel to be private is there any solution for this?
import configparser
import json
import re
from telethon.errors import SessionPasswordNeededError
from telethon import TelegramClient, events, sync
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon.tl.types import (PeerChannel)
api_id = *******
api_hash = ******
# Here you define the target channel that you want to listen to:
user_input_channel = 'https://t.me/<channel_id>'
client = TelegramClient('name', api_id, api_hash)
# Listen to messages from target Channel
@client.on(events.NewMessage(chats=user_input_channel))
async def newMessageListner(event):
# Get message text
newMessage = event.message.message
print(newMessage)
with client:
client.run_until_disconnected()
while trying with the channel in private I am getting this error message
Cannot find any entity corresponding to "https://t.me/<channel_id>"
Note:
Channel ID is delibrately masked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在频道ID之前添加-100,例如-100xxxxxxx
Add -100 before the channel Id like -100XXXXXXX