电报机器人不发送消息

时间:2021-05-27 12:21:43

标签: python-telegram-bot

我正在尝试执行这个简单的电报机器人,但没有输出,我不知道我做错了什么。这是代码:

from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext


def hello(update: Update, context: CallbackContext) -> None:
    update.message.reply_text(f'Hello {update.effective_user.first_name}')


updater = Updater('my_token')

updater.dispatcher.add_handler(hello)

updater.start_polling()
updater.idle()

1 个答案:

答案 0 :(得分:1)

我认为您在 add_handler 函数中遗漏了一些参数,因此应该如下所示:

updater.dispatcher.add_handler(CommandHandler('hello', hello))