Answer the question
In order to leave comments, you need to log in
TypeError: 'async_generator' object is not iterable?
I'm writing a bot on aiogram and I need to get all the chat participants. Since aiogram cannot get the list of participants, I need to get the list of participants through pyrogram and then pass it to the bot.
my code is
bot.py
from aiogram import Bot, Dispatcher, executor, types
import юзербот
бот = Bot(token=config.TOKEN)
диспетчер = Dispatcher(бот)
# код...
@диспетчер.message_handler(commands=['додати'], commands_prefix='+')
async def додати(message: types.Message):
текст = message.text
що = текст.split(" ")[1]
ід_чату = message.chat.id
print(текст, що)
if що == "юзера":
якого = текст.split(" ")[2]
if якого == "цього":
#код..
elif якого == "всіх":
print(await юзербот.учасники_чату(ід_чату))
#код..
if __name__ == '__main__':
executor.start_polling(диспетчер, skip_updates=True)
from pyrogram import Client, filters
from pyrogram.errors import FloodWait
app = Client("my_account")
async def учасники_чату(ід):
await app.start()
учасники = []
for учасник in app.iter_chat_members(ід):
учасники.append(учасник.user.id)
await app.stop()
return учасники
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py:409> exception=TypeError("'async_generator' object is not iterable")>
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 417, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 238, in process_updates
return await asyncio.gather(*tasks)
File "C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 259, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Program Files\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "бот.py", line 122, in додати
print(await юзербот.учасники_чату(-1001363517171))
File "C:\_myprog\_\python\_tg\_smails\_2\хз\юзербот.py", line 14, in учасники_чату
for учасник in app.iter_chat_members(ід):
TypeError: 'async_generator' object is not iterable
from pyrogram import Client, filters
from pyrogram.errors import FloodWait
app = Client("my_account")
def учасники_чату(ід):
app.start()
учасники = []
for учасник in app.iter_chat_members(ід):
учасники.append(учасник.user.id)
app.stop()
return учасники
print(учасники_чату(-1234..))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question