Reputation: 43
I need to send a premium emoji on the user's account using Pyrogram. I tried to send with send_message()
a list of MessageEntityCustomEmoji
and MessageEntity
. The first one gave the error 'MessageEntityCustomEmoji' object has no attribute '_client'
, and the second one sent a message without an emoji. How do I send them without errors?
Upvotes: 4
Views: 2765
Reputation: 56
After lots of research and suffering, the answer was:
...
my_emoji_str = "<emoji id=5310129635848103696>✅</emoji> And this is custom emoji in the text"
await app.send_message(message.chat.id, my_emoji_str)
This is basically a text formatting, here it is in HTML ParseMode of Pyrogram, but Pyrogram supports both Markdown and HTML formatting simultaneously out-of-the-box, and you also don't need to specify it in the parse_mode
argument.
And the id
is the custom_emoji_id
that you can find in the message
object if you don't know it yet. To know what to look for:
...
"text": "✅ Hello",
"entities": [
{
"_": "MessageEntity",
"type": "MessageEntityType.CUSTOM_EMOJI",
"offset": 0,
"length": 1,
"custom_emoji_id": 5310129635848103696 # <-- here you go
}
],
...
And.. That's it!
Upvotes: 4