Miguel Espinosa
Miguel Espinosa

Reputation: 9

using emoji python library with pyrogram

i am making a script for telegram using pyrogram, the problem comes when i try to use the emoji library. What I need is to demojize the texts that I receive from a bot to later process them, but using the function emoji.demojize("text") keeps throwing me the error: UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 2-3: unexpected end of data. This does not happen to me when I implement the emoji library in a bot using telebot, so I imagine the problem may be with pyrogram and how it solves the messages, I don't really know. please if anyone knows what it could be it would be very useful. In case u need it, the code goes something like this:

from pyrogram import Client, filters, idle
import emoji

app1 = Cliente('MyAccount', api_id, api_hash)

@app1.on_message(filters.chat("@somebot") & filters.incoming)
def listener(client, message):
    print(emoji.demojize(message.text))

app1.start()
idle()

Upvotes: -1

Views: 487

Answers (1)

Mehdi
Mehdi

Reputation: 11

try this , I had same problem and solve by this.

print(emoji.demojize(message.text.encode('utf-16').decode("utf-16")))

Upvotes: 1

Related Questions