V
V
venera0602021-01-12 19:32:13
Python
venera060, 2021-01-12 19:32:13

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)

5ffdce28c3101729180381.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BasiC2k, 2021-01-12
@venera060

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

S
soremix, 2021-01-12
@SoreMix

Does a person have a lastname at all? Which?
There is clearly not a string, it most likely has no name at all, None instead of it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question