【问题标题】:AttributeError: 'coroutine' object has no attribute 'users'AttributeError:“协程”对象没有属性“用户”
【发布时间】:2020-01-20 15:19:28
【问题描述】:

当我运行这段代码时:

from telethon import TelegramClient
from telethon.tl.functions.messages import AddChatUserRequest
from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest
client = TelegramClient('session_name',
api_id,
api_hash)
client.start()
contact = InputPhoneContact(client_id=0, phone=guest_phone_number, first_name="custom_first_name",  last_name="custom_last_name")
result = client(ImportContactsRequest([contact]))
client(AddChatUserRequest(user_id=result.users[0], fwd_limit=0, chat_id=group_id))

它给了我这个错误:

AttributeError: 'coroutine' object has no attribute 'users'

请帮忙(

【问题讨论】:

  • 请包含返回的错误的完整堆栈。

标签: python attributeerror telethon


【解决方案1】:

从您的代码看来,问题在于 client() 调用返回了结果,并且您希望结果变量具有一个用户项,该用户项是您试图获取其第一个元素的数组。您需要检查结果对象以查看它返回到您的程序时的样子。

【讨论】:

  • result =
  • 如果您执行 dir(result),它将为您提供对象具有的属性名称列表。这将表明它是否具有您可以使用的特定属性。我的猜测是这次你没有找回用户属性
猜你喜欢
  • 2021-11-20
  • 2021-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-02
  • 1970-01-01
  • 2012-12-01
  • 2021-04-19
相关资源
最近更新 更多