我的机器人通过一个函数传递一个简单的字符串(query.query),该函数返回一个“大”字典,里面有许多子字典(每个代表“卡”数据)。因为它现在正常工作,所有返回的子项的所有键和值都会在线显示(直到分页限制)。因此,例如,写入“blue”将返回卡名为==“blue”的所有子项的键:值对。
我希望机器人首先显示卡名称的内联结果,并在用户选择卡后,让机器人显示其余的卡数据,这样用户就可以选择在聊天中发送哪个部分。这看起来像是:
这是所述代码的片段。检查#comment以查看我认为它全部崩溃的地方
@bot.inline_handler(lambda query: len(query.query) > 3)
def query_card(inline_query):
temp_names_list = []
results_list = []
try:
sound_dict = scrape(inline_query.query)
for key, sub_dict in sound_dict.items():
temp_names_list.append(types.InlineQueryResultArticle(id=key, title=sub_dict['Name'], input_message_content=types.InputTextMessageContent(sub_dict['Name'])))
bot.answer_inline_query(inline_query.id, temp_names_list, cache_time=1)
#The code breaks down here since I haven't found a way of passing the result to ^ this answer_inline_query into the next part of the loop:
for key, sub_dict in sound_dict.items():
for k, v in sub_dict.items():
if k == ['message']['text']:
results_list.append(types.InlineQueryResultArticle(id=key+k, title=k, input_message_content=types.InputTextMessageContent(sub_dict['Name']+"\'s ["+k+"] bit:\n"+v)))
#results_list.append(types.InlineQueryResultVoice(id=k, voice_url=v, title="^ "+sound_dict['Name']+"\'s ["+k+"] bit:\n"+v, caption=sound_dict['Name']+"\'s ["+k+"] bit"))
bot.answer_inline_query(inline_query.id, results_list, cache_time=1)
except Exception as e:
print(e)