当您单击复制的文本时如何做到这一点 pytelegrambotapi

问题描述 投票:0回答:4

我正在给机器人写一封电报。我遇到了这样的问题。我需要机器人在单击复制的消息(文本)时发送一条消息(文本)(作为来自 @BotFather 的令牌)

python bots telegram telegram-bot py-telegram-bot-api
4个回答
22
投票

如果我理解正确的话,你希望发送一条消息,当用户按下它时,文本会自动复制到用户的剪贴板,就像 BotFather 发送 API 令牌一样?


这是通过 MarkDown

parse_mode
;
完成的 使用
&parse_mode=MarkDown
发送消息并将“可按”文本括在反引号 (
`
) 中:

Hi. `Press me!`!
https://api.telegram.org/bot<token>/sendMessage?chat_id=<id>&text=Hi! `Press me!`&parse_mode=MarkDown


编辑: 根据 OP 的评论,您正在寻找 解决方案。
从那里文档

bot.send_message(
    chat_id=chat_id, 
    text="*bold* _italic_ `fixed width font` [link](http://google.com).", 
    parse_mode=telegram.ParseMode.MARKDOWN
)

2
投票

您可以通过以下方式简单地编辑文本 写下“``,然后写下你的文字,然后再次写下这 3 个字符。 宾果!!!


1
投票

此解决方案适用于 Telegram Android 客户端以及 Windows 版 Telegram 桌面客户端。

bot = telebot.TeleBot(bot_token) #where bot_token is your unique identifier
text = "`" + text + "`" #now make sure the text has the backticks (leading and ending). 

然后一定要将解析模式设置为markdown(我使用的是V2)

bot.send_message(bot_chat_id, text, parse_mode='MarkdownV2') #chat_id is another unique identifier

我给自己发消息来演示:

只需单击该消息,它就会被复制到剪贴板!


0
投票

await botClient.SendTextMessageAsync(chatId, "Здравствуйте `текст для копирования` ", parseMode: ParseMode.Markdown);

© www.soinside.com 2019 - 2024. All rights reserved.