Answer the question
In order to leave comments, you need to log in
The problem with emoticons in the telegram bot, how to solve?
I'm using demojize to convert emoji to text, but it doesn't seem to work.
A man with emoticons in his name entered the bot and the bot crashed. Who knows how to fix this?
import telebot
from emoji import demojize
token = 'lalala'
bot = telebot.TeleBot(token)
new_offset = None
while True:
# приём сообщений
try:
updates = bot.get_updates(new_offset)
except Exception as e:
print(e)
continue
if not updates:
continue
for u in updates:
user_id = u.message.from_user.id
first_name = demojize(u.message.from_user.first_name)
last_name = demojize(u.message.from_user.last_name)
tg_username = u.message.from_user.username
message = demojize(u.message.text)
Answer the question
In order to leave comments, you need to log in
One emoji uses 4 bytes (sort of) instead of 2 per character. Accordingly, the bot can crash either when a variable overflows in the code, or when writing to the database (most likely).
Outputs:
1. Allow storage of 4 byte characters in the database;
2. Use a combination of substitute characters instead of emoji
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question