简体   繁体   English

python 中的 Telethon 机器人中的 aiter 错误

[英]error with aiter in telethon bot in python

i'm trying to loop inside my async function for my bot, and for the autodestruction function i have to iterate all the users and check if the user is an admin, done with this code:我正在尝试为我的机器人在我的异步 function 中循环,对于自动销毁 function 我必须迭代所有用户并检查用户是否是管理员,使用以下代码完成:

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

The issue comes when i try to run my code, returning this error当我尝试运行我的代码时出现问题,返回此错误

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

Any solutions?有什么解决办法吗?

get_participants returns a list, not an async iterator: 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

However this still won't work because the user and admins objects are probably different.但是,这仍然行不通,因为useradmins对象可能不同。 You should look for admins by comparing the id , not the entire user object.您应该通过比较id来查找admins ,而不是整个user object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM