I'm writing a python bot, and have this function, that is supposed to send an inline image, but it works strangely:
async def inline_catimg(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.inline_query.query
print("Cat called, query: "+query)
if not query:
return
print("Got past check")
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/A-Cat.jpg/2560px-A-Cat.jpg"
#url = "https://files.fm/f/38gfdcbw9t"
#url = "https://raw.githubusercontent.com/the-guy-bot/cats/main/our_cat_4.jpg"
#url = "D:/Access/cat_nobg.png"
results = []
results.append(
InlineQueryResultPhoto(
id=query+time.time.__str__(),
title='caps',
photo_url=url,
thumbnail_url=url
)
)
await context.bot.answer_inline_query(update.inline_query.id, results)
I also run it like this, if it matters:
if __name__ == '__main__':
application = ApplicationBuilder().token(TOKEN).build()
start_handler = CommandHandler('start', start)
inline_catimg_handler = InlineQueryHandler(inline_catimg)
application.add_handler(start_handler)
application.add_handler(inline_catimg_handler)
unknown_handler = MessageHandler(filters.COMMAND, unknown)
application.add_handler(unknown_handler)
application.run_polling()
And I import those libraries:
import logging
import time
from telegram import InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, Update
from telegram.ext import filters, MessageHandler, InlineQueryHandler, ApplicationBuilder, ContextTypes, CommandHandler
import random
What I want this code to do:
Create an inline python bot, that, if you type "@BotName" in any chat, would show a list of commands that this bot can do. Like "Turn this text to caps" or "Send a cat image".
Then you click on one of them, and it replaces your message with something (like a cat image or your text but in caps), based on the command that you chose, and sends it (it says above "via BotName").
The problem is that if I type "@BotName something" in any chat, it doesn't show the commands list. It just says "nothing here" or something like that. Sometimes it does show an image of a cat that sends it if you click on it, though I couldn't find out why.
Also, I have a few links there, and none of them work exept for Wikimedia one.
How can I fix it? Does anyone know how this stuff works (I have no idea what I am doing)?
Appreciate any help, as I don't know much about all this stuff