python - 使用 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
解决方案
检查您使用的是API中推荐的最新版本的 python 。
(python 3.8 或更高版本应该没问题)。
python3 --version
在终端中检查它。
如果不是3.8 or greater
更新它。
然后你必须重新下载电报机器人 API。
pip uninstall telebot
pip install pyTelegramBotAPI
推荐阅读
- safari - Safari 12 替换授权标头
- excel - 如何根据多个单元格值自动隐藏和取消隐藏excel中的行
- python - 当我没有为其分配名称时,输入返回错误的结果
- php - 为什么我会收到 sendmail 发送的邮件副本?
- pdf - 使用 imagemagick 将 pdf 转换为 jpg 时出现字体渲染错误
- oop - lua oop 开始
- javascript - 在Javascript中将平面数据数组转换为嵌套对象
- android - 动态解析 JSON | 安卓
- android - 图像识别和数据库,我从哪里开始?
- go - 在使用 gin gonic 进行负载测试期间打开的文件过多