помогите решить ошибку list indices must be integers or slices, not PollOption
мой код
async def check_polls_in_chat(client, message):
if message.chat.id == -1001998251987:
if message.poll:
poll_id = message.poll.id
options = message.poll.options
result = {}
for option in options:
result[option.text] = option.voter_count
correct_option_id = options[0]
await message.vote(correct_option_id)
await client.send_message(-1001772397440, f"correct_option_id: {correct_option_id}")
@app.on_message(filters.chat(-1001998251987))
async def handle_message(client, message):
await check_polls_in_chat(client, message)
app.run()
после запуска и отправки опроса в канал с айди -1001998251987 в терминале выдает ошибку
list indices must be integers or slices, not PollOption
Traceback (most recent call last):
File "C:\Users\VPC\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrogram\dispatcher.py", line 240, in handler_worker
await handler.callback(self.client, *args)
File "C:\pythonscripts\kek\gg.py", line 31, in handle_message
await check_polls_in_chat(client, message)
File "C:\pythonscripts\kek\gg.py", line 24, in check_polls_in_chat
await message.vote(correct_option_id)
File "C:\Users\VPC\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 3519, in vote
return await self._client.vote_poll(
File "C:\Users\VPC\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrogram\methods\messages\vote_poll.py", line 65, in vote_poll
options=[poll.options[option].data for option in options]
File "C:\Users\VPC\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrogram\methods\messages\vote_poll.py", line 65, in <listcomp>
options=[poll.options[option].data for option in options]
TypeError: list indices must be integers or slices, not PollOption
Ответы (1 шт):
Автор решения: CrazyElf
→ Ссылка
Нужно просто смотреть документацию
correct_option_id нужно брать из message.poll, а не из options
correct_option_id = message.poll.correct_option_id