Issue
I am newbie to Telegram Bot programming in Python. I created a simple bot @kawaikx_bot that has a /start command and can reply to any text input.
from telegram.ext import *
from datetime import datetime
weekdays = [0, 1, 2, 3, 4]
API_KEY = '********************************'
def start_command(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def handle_message(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def main():
updater = Updater(API_KEY)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
updater.start_polling()
updater.idle()
main()
I have enabled inline mode also. I am trying to pass a message to this bot from a group chat where bot is not a member by calling bot name and some text @kawaikx_bot hello. but it fails to send the reply.
I was expecting the reply 'Its a weekday today'
Can you help me figure out what's wrong with my code?
thanks in advance
Solution
CommandHandler
and MessageHandler
only catch updates that contain messages. Please have a look at this section of the official API docs as well as this PTB example. You should also look up the relevant classes & methods in the docs of PTB.
Disclaimer: I'm currently the maintainer of python-telegram-bot
.
Answered By - CallMeStag
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.