Sun*_*jan 2 python python-3.x telegram python-telegram-bot telegram-bot
我正在使用处理程序在Telegram机器人中工作。在他们使用命令后,我需要在其中获取用户名或用户ID。
我的密码
import telebot #Telegram Bot API
bot = telebot.TeleBot(<BotToken>)
@bot.message_handler(commands=['info'])
def send_welcome(message):
name = bot.get_me()
print(name)
bot.reply_to(message, "Welcome")
bot.polling()
Run Code Online (Sandbox Code Playgroud)
但是,我仅获得有关该机器人的信息。我无法获取有关使用处理程序的用户的信息。
输出值
{'first_name': 'SPIOTSYSTEMS', 'id': 581614234, 'username': 'spiotsystems_bot', 'is_bot': True, 'last_name': None, 'language_code': None}
Run Code Online (Sandbox Code Playgroud)
如何获得使用info
命令的用户的用户ID或名称?我应该使用哪种方法?请指教。
注意:
我的机器人与Telegram组链接。并且出于安全原因,我已从我的MVC中删除了Telegram TOKEN。
try this:
message.from_user.id
message.from_user.first_name
message.from_user.last_name
message.from_user.username
Run Code Online (Sandbox Code Playgroud)
or read this https://core.telegram.org/bots/api#user
归档时间: |
|
查看次数: |
4561 次 |
最近记录: |