如何通过电报机器人中的名字来称呼用户?

How to address user by it's first name in telegram bot?

我正在使用 pyTelegramBotApi(远程机器人)

我需要的是在用户按下 /start 后欢迎用户使用它的名字

@bot.message_handler(commands=['start'])
def start_command(message):
    bot.send_message(
        message.chat.id, 'Welcome!')

这只是发送消息 Welcome!,但我需要它看起来像 Welcome, %first_name%!

message 对象包含许多关于用户的信息; 要获得 first_name 使用; message.from_user.first_name

import telebot

bot = telebot.TeleBot("TOKEN")

@bot.message_handler(commands=['start'])
def send_welcome(message):

    bot.reply_to(message, "Hi " + message.from_user.first_name + "!")

bot.polling()

如果您对所有选项都感到好奇,最简单的方法是 print() 对象;

def send_welcome(message):
    print(message.from_user)