Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The same phrase is repeating while using different command

I’m developing a telegram bot. I do this on my code and the question is, why my bot repeat the same first phrase when I put the second command?

TOKEN_BOT = "secret token"
bot = telebot.TeleBot(TOKEN_BOT)

@bot.message_handler(commands=["hello", "start"])
def send(message):
    bot.reply_to(message, "Welcome, I am RIOPy! BOT designed to organize your SME to your liking. To start write / start and we will get to work.")

if message == "start":
        enviar_start(message)

bot.polling()

def enviar_start (message):
    bot.reply_to(message, "Great! wait 5 seconds.")

#HERE DATABASE CODE

time.sleep(5)
bot.reply_to, "DATABASE CREATED"

bot.polling()

PS: The code is working now. I deleted bot.pulling() under the if, and i put the /hello and /start commands in 2 differents lines.

@bot.message_handler(commands=["hello"])
def send(message):
    bot.reply_to(message, "Welcome, I am RIOPy! BOT designed to organize your SME to your liking. To start write / start and we will get to work.")

if message == "start":
        enviar_start(message)

@bot.message_handler(commands=["start"])
def enviar_start (message):
    bot.reply_to(message, "Great! wait 5 seconds.")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The first thing your bot says when you send the /start command is also the first thing it says when you send the /hello command, because your bot’s message handler for the /hello command is also the message handler for the /start command. To fix this, you need to create two separate message handlers, one for the /hello command and one for the /start command.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading