【问题标题】:python-telegram-bot error inline : input message content is not specifiedpython-telegram-bot 错误内联:未指定输入消息内容
【发布时间】:2021-10-07 02:01:28
【问题描述】:

我有一个函数,它接受一个字符串并在字典中搜索它,然后将结果作为字符串返回。我搜索了很多,但我无法学习如何使用内联方法向用户显示函数的输出。 我使用 python-telegram-bot 库。这是我写的返回响应函数结果的代码。

def inlinequery(update, context: CallbackContext) :
    query = update.inline_query.query
    if query == "":
        return

    results = [
        InlineQueryResultArticle(
            id=str(uuid4()),
            title="find this class code",
            description='example 1322008',
            input_message_content=InputTextMessageContent(
                response(query)
            )
        )
    ]
    update.inline_query.answer(results)

我希望将查询结果作为内联机器人接收。有时它可以工作,但会出现此错误:

root - 错误 - 更新 {'inline_query': {'id': '701438966003659473', 'offset': '', 'query': '1322008', 'chat_type': 'private', 'from': { 'is_bot': False, 'id': 1633163216, 'first_name': '', 'username': '', 'language_code': 'fa'}}, 'update_id': 331490925} 造成error Can't parse inline query result: input message content is not specified

【问题讨论】:

  • 请告诉我们rensponse函数的定义
  • def response(code): if code.isdigit() and len(code) == 7: return f"{code} found" else: return f"{code} not found"跨度>
  • 看起来不错,因为它在任何情况下都会返回一个字符串。我也无法重现该问题。你能显示完整的回溯吗?您必须为此停用错误处理程序,因为它隐藏了回溯。
  • 对不起,我可能做得不对,但这是一个错误。 ibb.co/dJXGjtR
  • 嗯,这也没有透露任何信息……那么我很抱歉,但我不知道出了什么问题

标签: python telegram-bot python-telegram-bot


【解决方案1】:

问题出在我的响应函数上,它有时会返回 None 类型...

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2015-10-10
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 2021-07-12
  • 2018-03-31
  • 2020-07-03
  • 1970-01-01
  • 2017-05-13
相关资源
最近更新 更多