无法从文件加入聊天(pyrogram)
cant join chat from a file (pyrogram)
我正在尝试使用 Pyrogram 框架从包含大量 link 组的 txt 文件加入电报群聊。
这是我的代码:
links = open('.../Desktop/Tel_Links/Links.txt')
app = Client(
"My_Account",
api_id = API,
api_hash ="API_Hash"
)
with app:
for line in links.readline():
app.join_chat()
但是当我这样做时,我得到了这个错误:
Exception has occurred: UsernameInvalid
[400 USERNAME_INVALID]: The username is invalid (caused by "contacts.ResolveUsername")
之后我尝试在 app.join_chat("link") 中输入 link 而不是 app.join_chat( links.readline())
像这样:
app = Client(
"My_Account",
api_id = API,
api_hash ="API_Hash"
)
with app:
app.join_chat('django')
效果很好 但是 我不想手动添加所有这些因为有很多 link 我需要从文件中导入它们.
请帮我
谢谢
您忘记将 line
传递给 join_chat:
with app:
for line in links.readlines():
app.join_chat(line.rstrip()) # pass line to method
你必须在传递之前用 rstrip 删除尾随的换行符。
编辑
顺便说一句:在你的情况下应该是 readlines()
而不是 readline()
。
我正在尝试使用 Pyrogram 框架从包含大量 link 组的 txt 文件加入电报群聊。 这是我的代码:
links = open('.../Desktop/Tel_Links/Links.txt')
app = Client(
"My_Account",
api_id = API,
api_hash ="API_Hash"
)
with app:
for line in links.readline():
app.join_chat()
但是当我这样做时,我得到了这个错误:
Exception has occurred: UsernameInvalid
[400 USERNAME_INVALID]: The username is invalid (caused by "contacts.ResolveUsername")
之后我尝试在 app.join_chat("link") 中输入 link 而不是 app.join_chat( links.readline())
像这样:
app = Client(
"My_Account",
api_id = API,
api_hash ="API_Hash"
)
with app:
app.join_chat('django')
效果很好 但是 我不想手动添加所有这些因为有很多 link 我需要从文件中导入它们. 请帮我 谢谢
您忘记将 line
传递给 join_chat:
with app:
for line in links.readlines():
app.join_chat(line.rstrip()) # pass line to method
你必须在传递之前用 rstrip 删除尾随的换行符。
编辑
顺便说一句:在你的情况下应该是 readlines()
而不是 readline()
。