【发布时间】: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