为什么 telethon 在尝试从电报组获取用户时显示错误?
我正在尝试使用电报机器人从群组中获取用户。我正在使用 python 的 telethon 库来实现此目的。这是代码和完整的错误消息 -
from telethon import TelegramClient, events
API_ID = 123
API_HASH = '##'
BOT_TOKEN ="##"
bot = TelegramClient('bot', API_ID, API_HASH)
bot.start(bot_token=BOT_TOKEN)
async def Get_Random():
users = await bot.get_participants(-123)
print(users[0].first_name)
for user in users:
if user.username is not None:
print(user.username)
bot.loop.run_until_complete(Get_Random())
完整错误 -
telethon.errors.rpcerrorlist.PeerIdInvalidError: An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations) (caused by GetFullChatRequest)
机器人已经是该组的管理员。
I am trying to get users from a group using a telegram bot . I am using python's telethon library for this purpose . Here is the code and the full error message -
from telethon import TelegramClient, events
API_ID = 123
API_HASH = '##'
BOT_TOKEN ="##"
bot = TelegramClient('bot', API_ID, API_HASH)
bot.start(bot_token=BOT_TOKEN)
async def Get_Random():
users = await bot.get_participants(-123)
print(users[0].first_name)
for user in users:
if user.username is not None:
print(user.username)
bot.loop.run_until_complete(Get_Random())
Full error -
telethon.errors.rpcerrorlist.PeerIdInvalidError: An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations) (caused by GetFullChatRequest)
Bot is already an admin of the group .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何被卡住并查看此内容的人,您需要成为您正在为其获取数据的电报组的一部分。加入该电报组解决了我的错误。
For anyone who is stuck and viewing this , You need to be part of the telegram group for which you are fetching the data . Joining that telegram group resolved my error .