Hi! For a month now I have been doing tests with a bot, however for 3/4 days when I try to start the bot it does not respond to any command on the telegram and I do not know why. Could anyone help me? To start the bot I type the command python3 (file).
The code (I remove the text that the bot should send.)
from telegram import (Update, InlineKeyboardButton, InlineKeyboardMarkup, ParseMode)
from telegram.ext import (Updater, CommandHandler, CallbackContext, ConversationHandler, CallbackQueryHandler, MessageHandler, Filters)
from datetime import datetime, timezone
def help(update: Update, context: CallbackContext):
update.message.reply_text(text=)
def start(update: Update, context: CallbackContext):
testo_del_messaggio = """ """
pulsanti = [[InlineKeyboardButton("Prenota",callback_data="1"),
InlineKeyboardButton("annulla",callback_data="2")
]]
markup =InlineKeyboardMarkup(pulsanti)
update.message.reply_text(text=testo_del_messaggio,reply_markup=markup, parse_mode=ParseMode.MARKDOWN_V2)
return "1"
def Prenota(update: Update, context: CallbackContext):
query = update.callback_query
us_id = update.callback_query.from_user.id
global pp
if pp<10:
query.answer()
context.bot.send_message(chat_id=us_id, text= """ """
return "2"
elif pp>=10:
query.answer()
context.bot.send_message(chat_id=us_id, text= """ """
def annulla(update: Update, context: CallbackContext):
query = update.callback_query
query.answer()
us_id = update.callback_query.from_user.id
context.bot.send_message(chat_id=us_id, text= """annullato!""")
return ConversationHandler.END
def cancella(update: Update, context: CallbackContext):
update.message.reply_text(text="addio")
return ConversationHandler.END
def prendinomeIscritti(update: Update, context: CallbackContext):
text = update.message.text
if text.isalpha():
global pp
pp+=1
iscritti.append(text)
print(iscritti)
update.message.reply_text(text=""" """
return ConversationHandler.END
else:
update.message.reply_text(text="""Inviami il tuo nome""")
return "2
def prendinomeNonIscritti(update: Update, context: CallbackContext):
text = update.message.text
if text.isalpha():
global pp
pp+=1
non_iscritti.append(text)
print(iscritti,non_iscritti)
update.message.reply_text(text=""" """)
return ConversationHandler.END
else:
update.message.reply_text(text="""Inviami il tuo nome""")
return "3"
pp = 0
iscritti = []
non_iscritti=[]
def ping(update: Update, context: CallbackContext) -> None:
"""
This function is used to check the ping
INPUT:
- update [dict] of all the informations [str] of the received message generated by telegram
with Update
- context [Telegram] is used to send the message
"""
t=update.message.date
temp=datetime.now(timezone.utc)
temp=abs(temp-t)
s=temp.seconds
ms=temp.microseconds
update.message.reply_text(text="pong: {}.{} sec".format(s,ms))
TOKEN = ""
#Now I define the bot
updater = Updater(token=TOKEN,use_context=True)
#Now I define the ConversationHandler for the /start command
start_handler = ConversationHandler(
entry_points=[CommandHandler("start",start)],
states={
"1": [
CallbackQueryHandler(Prenota,pattern="1"),
CallbackQueryHandler(annulla,pattern="2"),
],
"2":[
MessageHandler(Filters.text & ~Filters.command,prendinomeIscritti)
],
"3":[
MessageHandler(Filters.text & ~Filters.command,prendinomeNonIscritti)
],
},
fallbacks=[CommandHandler('cancel', cancella)],
)
dispatcher.add_handler(start_handler)
#Now I start the bot
updater.start_polling()
#That's for the clean quit of the bot
updater.idle()
dispatcher = updater.dispatcher
#Now I define the CommandHandler for the /help command
help_handler = CommandHandler('help', help)
dispatcher.add_handler(help_handler)
#creo il filtro
whitelist=[900834785,544187443]
filtro = Filters.chat()
for person in whitelist:
filtro.add_chat_ids(person)
#Now I define the CommandHandler for the /ping command
ping_handler = CommandHandler('ping', ping, filtro)
dispatcher.add_handler(ping_handler)