如何使用我的电报机器人使用他们的用户名向某人发送消息 [英] How can I send a message to someone with my telegram bot using their Username

查看:53
本文介绍了如何使用我的电报机器人使用他们的用户名向某人发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用telepot python 库,我知道当你有某人的用户ID(这是一个数字)时你可以发送消息.我想知道是否可以在没有 UserID 的情况下向某人发送消息,而仅使用他们的用户名(以@"开头的那个),另外是否有办法将用户名转换为 UserID.

I am using the telepot python library, I know that you can send a message when you have someone's UserID(Which is a number). I wanna know if it is possible to send a message to someone without having their UserID but only with their username(The one which starts with '@'), Also if there is a way to convert a username to a UserID.

推荐答案

您不能使用 @username 形式的用户名向用户发送消息,您只能向频道发送消息您的机器人是其管理员的用户名.Telegram bot api 使用 chat_id 标识符来发送消息.如果想实现用户的chat_id,可以使用telegram-cli,但这一点也不容易,因为那个项目已经停产了,你应该自己调试.在您的情况下,您应该执行以下命令:

You can't send message to users using their username that is in form of @username, you can just send messages to channel usernames which your bot is administrator of it. Telegram bot api uses chat_id identifier for sending messages. If you want to achieve chat_id of users, you can use telegram-cli, but it's not easy at all because that project is discontinued and you should debug it yourself. in your case you should do following command:

> resolve_username vahid_mas

输出将是这样的:

{
  "user": {
    "username": "Vahid_Mas",
    "id": "$010000006459670b02c0c7fd66d44708",
    "last_name": "",
    "peer_type": "user",
    "print_name": "Vahid",
    "flags": 720897,
    "peer_id": 191322468,
    "first_name": "Vahid",
    "phone": "xxxxxxx"
  },
  "online": false,
  "event": "online-status",
  "state": -1,
  "when": "2017-01-22 17:43:16"
}

这篇关于如何使用我的电报机器人使用他们的用户名向某人发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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