Python 用电视电报机器人发送投票

Python 用电视电报机器人发送投票,python,telegram,telegram-bot,telethon,Python,Telegram,Telegram Bot,Telethon,我如何发送投票?我正在尝试以下代码,但它不返回任何错误,并且不会发送轮询: from typing import Optional from telethon.sync import TelegramClient from telethon.tl.types import * from telethon.tl.functions.messages import * def _build_poll(question: str, *answers: str, closed: Optional[bo

我如何发送投票?我正在尝试以下代码,但它不返回任何错误,并且不会发送轮询:

from typing import Optional
from telethon.sync import TelegramClient
from telethon.tl.types import *
from telethon.tl.functions.messages import *

def _build_poll(question: str, *answers: str, closed: Optional[bool] = None,
                id: int = 0) -> InputMediaPoll:
    """Build a poll object."""
    return InputMediaPoll(Poll(
        id=id, question=question, answers=[
            PollAnswer(text=i, option=bytes([idx]))
            for idx, i in enumerate(answers)
        ],
        closed=closed
    ))

poll = _build_poll(f"Question", "Answer 1", "Answer 2", "Answer 3")
message = client.send_message(-325188743, file=poll)

是否有更好的方法使用telethon提交民意测验?

要发送民意测验,您需要使用中找到的构造民意测验媒体对象

在您的情况下,您需要一个发送示例,即发送,如示例所示:

等待客户端。发送消息('@username',file=types.InputMediaPoll( poll=types.poll( id=…,#类型:长(随机id) 问题=…,#类型:字符串(问题) 答案=…#类型:轮询答案列表(最多10个答案) ) )) 使用实际值:

从telethon.tl.types导入InputMediaPoll,Poll,PollAnswer
等待客户端。发送消息(“telethonofftopic”,file=InputMediaPoll(
民意测验(
id=53453159,
问=“现在是2020年吗?”,
答案=[PollAnswer('Yes',b'1'),PollAnswer('No',b'2')]
)
))

BadRequestError:RPCError 400:POLL\u OPTION\u无效(由SendMediaRequest引起)您发布的代码引发该错误。看起来
b'random\u data\u 1'
无效。我对答案进行了编辑以使其生效。