I want to make this work in inline mode so when someone types ‘/tip’ in an inline query, it shows the same result. For other input, it should return nothing.
I looked at the library documentation and found this example:
When I tried replacing user_query.upper() with my get_tip(update, context) function, I get type errors. I think I’m missing something about how inline queries work differently from regular commands.
The problem is inline queries work totally differently than regular commands. Your get_tip function returns None and sends messages directly, but inline queries need you to build result objects and return them with answer_inline_query. I hit this same wall when I converted my bot commands to inline mode. You’ve got to pull out just the tip selection logic and wrap it in an InlineQueryResultArticle. Here’s what worked for me: check if the query matches ‘/tip’, read your file, grab a random tip, then create the result object with that tip as InputTextMessageContent. Your inline handler should always call answer_inline_query - even for empty results when queries don’t match. Don’t try reusing your existing command function. They’re built completely differently.
You’re mixing up command handlers with inline handlers. Inline queries don’t have effective_chat.id - that’s only for regular messages. Check if user_query == '/tip' first, then read your tip content and wrap it in InlineQueryResultArticle. Don’t call your existing get_tip function - just copy the file reading part into your inline handler.
The problem is inline queries work totally different from regular commands. Your get_tip function sends messages directly, but inline queries need to return results users can pick from. Here’s how to fix it: python def inline_tip(update, context): user_query = update.inline_query.query.strip(); if user_query != '/tip': context.bot.answer_inline_query(update.inline_query.id, []); return; with open("tips.txt", "r") as tip_file: all_lines = tip_file.readlines(); selected_tip = random.choice(all_lines); result_list = [ InlineQueryResultArticle( id="tip_" + str(random.randint(1000, 9999)), title="Random Tip", input_message_content=InputTextMessageContent(selected_tip) ) ]; context.bot.answer_inline_query(update.inline_query.id, result_list); Instead of sending messages directly, inline queries return selectable results. When someone picks your result, InputTextMessageContent is what actually gets sent.