我正在使用 pyTelegramBotApi (telebot)
我需要的是在用户按下 /start 后欢迎用户使用它的名字
@bot.message_handler(commands=['start'])
def start_command(message):
bot.send_message(
message.chat.id, 'Welcome!')
这只是发送消息Welcome!
,但我需要它看起来像Welcome, %first_name%!
我正在使用 pyTelegramBotApi (telebot)
我需要的是在用户按下 /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)