python-3.x - 如何使用电视马拉松在消息中插入用户个人资料或聊天的链接?

标签 python-3.x hyperlink telethon

在电视马拉松中撰写新消息我试图制作类似“聊天(链接)中的用户(链接)发布了某些内容”的内容,但失败了。

根据https://github.com/LonamiWebs/Telethon/wiki/Special-links ,我尝试过 tg://user?id=123 和 tg://openmessage?chat_id=123 等链接,但这提供的文本链接不起作用。

示例如下:

@client.on(events.NewMessage)
async def handler(event):
    sender = await event.get_sender()
    sender_id = event.sender_id
    sender_link = 'tg://user?id=' + str(sender_id)
    payload = '[%s] (%s) said something' % (sender.first_name, sender_link)

我期待收到一 strip 有超链接用户名的消息,但收到 [Alex] (tg://user?id=123),并且该链接无处可去。

最佳答案

您需要删除 [...](...) 之间的空格。您应该有[%s](%s)

关于python-3.x - 如何使用电视马拉松在消息中插入用户个人资料或聊天的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407042/

相关文章:

Python查找重复项: Find out if there are duplicate numbers and the index diff is at most k

python - 在 Python 中训练 NGramModel

python - 如何创建一个返回值的异步任务?

Python3 + Gunicon 19.9 + Django 2.0 不打印我的日志,但打印 django.request

hyperlink - 将标题转换为链接在 Lightbox 2.51 中不起作用

html - 基本标签与书签链接混淆

c++ - 编译头文件定义了一个模板类,其中还包括其他头文件

python - 错误消息堵塞 Telethon 导致安全错误 : Server sent a very new message xxxxx was ignored

api - InputPhoneContact 没有 len()

python - 继承 `int` 的类获得奇怪的幽灵般的变量赋值