python - 语法错误:无效错误。电报机器人
问题描述
写电报机器人。这里代码:
import telebot
import time
token = 'my token'
bot = telebot.TeleBot(token)
def find_at(msg):
for text in msg:
if '@' in text:
return text
@bot.message_handler(commands=['start'])
def handle_text(message):
bot.send_message(message.chat.chat_id, "Welcome! Let start, use command /help to see my functional.")
@bot.message_handler(commands=['help'])
def handle_text(message):
bot.send_message(message.chat_id, "To use this bot, send it a username.")
@bot.message_handler(func=lambda msg: msg.text is not None and '@' is in msg.text)
def at_answer(message):
texts = message.text.split()
at_text = find_at(texts)
bot.reply_to(message, 'https://instagram.com/{}'.format(at_text[1:]))
当我开始时main.py
,我得到错误:
@bot.message_handler(func=lambda msg: msg.text is not None and '@' is in msg.text)
SyntaxError: invalid syntax`
如何解决?请帮忙!
解决方案
is
从行中删除@bot.message_handler(func=lambda msg: msg.text is not None and '@' is in msg.text)
为:
@bot.message_handler(func=lambda msg: msg.text is not None and '@' in msg.text)
解释:
要检查文本中的该字符是否只需使用in
推荐阅读
- c - 林间空地键盘(转义,箭头)加速器
- sql - 选择除特定列中具有最大值的行之外的所有内容
- eclipse - 运行 build.xml 时构建失败
- javascript - 添加作为命令行参数给出的数字的推荐方法(速度,清晰度)
- r - 按组生成元素列表的函数 (R)
- ios - iOS 类似 Android Animator(Set) 的复杂动画协调
- typescript - 带有动态分配的 Typescript 2.9 错误
- sql - 使用 Sql Agent 部署 Sql Analysis Services 时出错
- ffmpeg - 如何在不重新启动 ffmpeg 命令正在播放的视频流的情况下更改视频的 fps?
- java - 使用布尔值或对象字段反序列化 json