[Python] Telebot: replying to user with the same message

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am making a translator bot with inline button using Telebot. When user sends message the bot will offer him to choose a language. And when user has chosen a language, bot should translate it.

    What should I write to text variable in the code below?

    How can I describe the user message/input?

    import telebot
    from telebot import types
    from googletrans import Translator
    BOT_TOKEN = "<Bot_Token>"
    bot = telebot.TeleBot(BOT_TOKEN)

    key =types.InlineKeyboardMarkup()
    btn1=types.InlineKeyboardButton(text ="Amharic" , callback_data="am")
    btn2=types.InlineKeyboardButton(text =" Arabic" , callback_data="ar")
    btn3=types.InlineKeyboardButton(text =" Hindi" , callback_data="hi")
    key.add(btn1,btn2,btn3)
    @bot.callback_query_handler(func=lambda call:True)
    def callback(call):
    #here is my question, what does i have to write in text variable ?
    text= call.message.chat.text
    #?????????
    if call.data=="am":
    translator=Translator()
    translation=translator.translate(text,dest="am")
    bot.send_message(call.message.chat.id,text)

    @bot.message_handler(commands = ["start"])
    def welcome (message):
    bot.send_message(message.chat.id,'HELLO!!! send a message!')
    @bot.message_handler(func=lambda call:True)
    def choose(message):
    bot.send_message(message.chat.id,"select your language:",reply_markup=key)
    bot.infinity_polling()

    Continue reading...

Compartilhe esta Página