【问题标题】:Send premium-emoji with Pyrogram使用 Pyrogram 发送高级表情符号
【发布时间】:2023-01-14 21:41:25
【问题描述】:

我需要使用 Pyrogram 在用户帐户上发送高级表情符号。我试图用send_message()发送MessageEntityCustomEmojiMessageEntity的列表。第一个报错'MessageEntityCustomEmoji' object has no attribute '_client',第二个发了没有表情的消息。我如何无误地发送它们?

【问题讨论】:

  • 请提供足够的代码,以便其他人可以更好地理解或重现问题。

标签: python telegram pyrogram


【解决方案1】:

经过大量的研究和痛苦,答案是:

...

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)

这基本上是一个文本格式,这里是在 Pyrogram 的 HTML ParseMode 中,但是 Pyrogram 开箱即用地同时支持 Markdown 和 HTML 格式,而且你也需要在 parse_mode 参数中指定它。

id就是custom_emoji_id,如果你还不知道,你可以在message对象中找到它。要知道要寻找什么:

...
"text": "✅ Hello",
"entities": [
    {
        "_": "MessageEntity",
        "type": "MessageEntityType.CUSTOM_EMOJI",
        "offset": 0,
        "length": 1,
        "custom_emoji_id": 5310129635848103696 # <-- here you go
    }
],
...

而且..就是这样!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2023-03-14
    • 2022-11-10
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    相关资源
    最近更新 更多