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?
JavaScript
x
19
19
1
TOKEN_BOT = "secret token"
2
bot = telebot.TeleBot(TOKEN_BOT)
3
4
@bot.message_handler(commands=["hello", "start"])
5
def send(message):
6
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.")
7
8
bot.polling()
9
10
def enviar_start (message):
11
bot.reply_to(message, "Great! wait 5 seconds.")
12
13
#HERE DATABASE CODE
14
15
time.sleep(5)
16
bot.reply_to, "DATABASE CREATED"
17
18
bot.polling()
19
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.
JavaScript
1
8
1
@bot.message_handler(commands=["hello"])
2
def send(message):
3
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.")
4
5
@bot.message_handler(commands=["start"])
6
def enviar_start (message):
7
bot.reply_to(message, "Great! wait 5 seconds.")
8
Advertisement
Answer
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.