pyTelegramBotAPI使用if / elif / else构造在消息文本中搜索

时间:2018-06-17 08:12:41

标签: python telegram-bot

人。我对使用Python 3.6.5的pyTelegramBotAPI库的行为有疑问。它是一个与Telegram API一起使用的库。

有我的代码:

import telebot
from telebot.types import Message
from telebot import types

TOKEN = 'TOCKEN_HERE'
bot = telebot.TeleBot(TOKEN)

markup = types.ReplyKeyboardMarkup()
itembtn_privet = types.KeyboardButton('If')
itembtn_more = types.KeyboardButton('Elif')
itembtn_else = types.KeyboardButton('Else')
markup.row(itembtn_privet, itembtn_more, itembtn_else)
bot.send_message(chat_id_here, "Choose one option:", reply_markup=markup)


@bot.message_handler(commands=['start', 'help'])
def command_handler(message: Message):
    bot.reply_to(message, 'The is no answer, sorry(')


@bot.edited_channel_post_handler(content_types=['text'])
@bot.message_handler(content_types=['text'])
def echo_messages(message: Message):
    text = message.text
    if text == 'If' or 'if':
         bot.reply_to(message, 'If')
    elif text == 'Elif' or 'elif':
         bot.reply_to(message, f'Elif')
    else:
         bot.reply_to(message, 'Else')

bot.polling(timeout=60)

我的问题 - 我可以选择任何选项,但qnswer始终是"如果"。为什么我无法使用if / elif / else来管理答案?我该如何解决?我需要使用正则表达式(请不要)?

感谢您的关注。

1 个答案:

答案 0 :(得分:0)

变化非常简单:

if text == 'If':

notify