首页 > 解决方案 > 使用 message_handler (telebot) 时出错

问题描述

我尝试使用 pyTelegramBotAPI、telebot 创建自己的 Telegram 机器人。这是我的代码:

import telebot

bot = telebot.TeleBot("xxxx")

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")

bot.polling()

但是,当我运行它时,我得到了错误:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import telebot
  File "/home/rm_coder/.local/lib/python3.8/site-packages/telebot/__init__.py", line 816
    @util.async()
          ^
SyntaxError: invalid syntax

标签: pythontelegrampy-telegram-bot-api

解决方案


检查您使用的是API中推荐的最新版本的 python 。
(python 3.8 或更高版本应该没问题)。

python3 --version在终端中检查它。

如果不是3.8 or greater更新它。

然后你必须重新下载电报机器人 API。

pip uninstall telebot

pip install pyTelegramBotAPI


推荐阅读