'How to use an emoji as prefix instead of "/" on Telebot
I'm trying to write a Telegram bot to help a friend with his online buisness.
I'm trying to make an interactive menu, but if I try to use an emoji as a prefix the @bot.message_handler doesn't read the user input, resulting in the menu not updating.
Working code (with "/" as command prefix):
@bot.message_handler(commands=["Menu"])
def startMenu(msg):
#########-START MENU-#########
markup = keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True, one_time_keyboard=True)
btnHelp = types.KeyboardButton("/Help")
##############################
markup.add(btnHelp)
bot.send_message(msg.chat.id, text="Need help?"
, reply_markup=markup)
@bot.message_handler(commands=["Help"])
def helpMenu(msg):
markup = keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True, one_time_keyboard=True)
btnBack = types.KeyboardButton("/Menu")
markup.add(btnBack)
bot.send_message(msg.chat.id, text="Test Help"
, reply_markup=markup)
Faulty code (with UNICODE emoji as prefix):
@bot.message_handler(commands=["Menu"])
def startMenu(msg):
#########-START MENU-#########
markup = keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True, one_time_keyboard=True)
btnHelp = types.KeyboardButton("\U0001F60Help")
##############################
markup.add(btnHelp)
bot.send_message(msg.chat.id, text="Need help?"
, reply_markup=markup)
@bot.message_handler(commands=["\U0001F60Help"])
def helpMenu(msg):
markup = keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True, one_time_keyboard=True)
btnBack = types.KeyboardButton("/Menu")
markup.add(btnBack)
bot.send_message(msg.chat.id, text="Test Help"
, reply_markup=markup)
Solution 1:[1]
You can use regular expression as there is no native way to change the prefixes:
@bot.message_handler(regexp="^\U0001F60H(your_command)")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | roj1512 |
