Telegram bot:如何通过用户名(而不是用户名)提及用户 [英] Telegram bot: How to mention user by its id (not its username)

查看:144
本文介绍了Telegram bot:如何通过用户名(而不是用户名)提及用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个电报机器人并使用 sendMessage 方法发送消息.使用@username很容易提及用户,但是当他们没有用户名时如何提及用户?

I am creating a telegram bot and using sendMessage method to send the messages. it is easy to mention user using @username, But how to mention user when they don't have username?

如果使用telegram app/web,我们可以通过@integer_id (name) 提及用户,telegram app/web 会将其转换为可点击的文本.integer_id 会在我们选择用户时自动生成,输入@后.

If using the telegram app/web, we can mentioned the user by @integer_id (name), and telegram app/web will convert it into clickable text. integer_id will be generated automatically when we select the user, after typing @.

另一个背景:我正在尝试使用 forceReply 并且我想定位用户,如果他们有用户名,我可以通过在 sendMessage 方法的文本中提及他们来轻松定位他们.

another background: I am trying to use forceReply and I want to target user, if they have username, I can easily target them, by mentioning them on the text on sendMessage method.

我正在创建的机器人是一个类似于机器人的测验".在每个玩家需要轮流的情况下,机器人正在向他们发送问题,机器人的每个消息都将针对不同的玩家.

the bot I am creating is a "quiz" like bot. where each player need to take turn, and the bot is sending them the question, each msg from bot will target different player.

注意:我没有禁用 Privacy Mode,我不希望电报用我不需要的 msg 轰炸我的服务器.它使我廉价的讨厌的服务器超载.所以,禁用它不是一种选择.

NOTE: I am not disabling the Privacy Mode, I don't want telegram bombing my server with msg I don't need. it was overloading my cheap nasty server. so, disabling it not an option.

我愿意接受其他解决方案,机器人可以在其中收听选定的播放器.

I am open for other solution, where the bot can listen to selected player.

谢谢.

更新 21/10:他们说,我已经与 BotSupport 谈过电报,目前 Bot 无法在没有用户名的情况下提及用户.

UPDATE 21/10: I've spoke to BotSupport for telegram, they said, for now Bots can't mention user without username.

所以在我的情况下,我仍然继续使用 forceReply,并且还给没有用户名的用户发送了一个简短的 msg 来设置它,这样他们就可以从 forceReply 函数.

so in my case, I still keep using forceReply, and also, gave a short msg to user which doesn't have username to set it up, so they can get the benefit from forceReply function.

推荐答案

根据官方文档 可以通过带有标记的数字 ID 来提及用户:

According to official documentation it is possible to mention user by its numerical id with markup:

[内联提及用户](tg://user?id=123456789)

这篇关于Telegram bot:如何通过用户名(而不是用户名)提及用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆