【问题标题】:error with aiter in telethon bot in pythonpython中telethon bot中的aiter错误
【发布时间】:2022-09-27 22:49:33
【问题描述】:

我试图在我的机器人的异步函数中循环,对于自动销毁函数,我必须迭代所有用户并检查用户是否是管理员,使用以下代码完成:

all_participants = await bot.get_participants(group, aggressive=False)
    admins = bot.iter_participants(group, filter=ChannelParticipantsAdmins)
    print(\'[+] Banno gli utenti...\')
    async for user in all_participants:
        if not user in admins:
            pass

当我尝试运行我的代码时出现问题,返回此错误

Traceback (most recent call last):
  File \"/home/elias/.local/lib/python3.8/site-packages/telethon/client/updates.py\", line 467, in _dispatch_update
    await callback(event)
  File \"bannerbot.py\", line 31, in pyro
    async for user in all_participants:
TypeError: \'async for\' requires an object with __aiter__ method, got TotalList

有什么解决办法吗?

    标签: python bots telegram telethon


    【解决方案1】:

    get_participants 返回一个列表,而不是异步迭代器:

    all_participants = await bot.get_participants(group, aggressive=False)
    admins = await bot.get_participants(group, filter=ChannelParticipantsAdmins)
    #                  ^^^ get, not iter
    print('[+] Banno gli utenti...')
    for user in all_participants:
    # ^ removed the async
        if not user in admins:
            pass
    

    然而这仍然行不通,因为useradmins 对象可能不同。您应该通过比较 id 而不是整个 user 对象来查找 admins

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 2022-11-30
      • 2022-01-07
      • 1970-01-01
      • 2023-03-16
      • 2021-07-30
      • 2017-11-05
      • 2020-09-26
      • 1970-01-01
      相关资源
      最近更新 更多