[英]error with aiter in telethon bot in python
我正在嘗試為我的機器人在我的異步 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
當我嘗試運行我的代碼時出現問題,返回此錯誤
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
有什么解決辦法嗎?
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
但是,這仍然行不通,因為user
和admins
對象可能不同。 您應該通過比較id
來查找admins
,而不是整個user
object。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.