Syntax error: invalid error. Telegram bot
Syntax error: invalid error. Telegram bot
编写电报机器人。这里的代码:
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`
如何解决?请帮忙!
从行 @bot.message_handler(func=lambda msg: msg.text is not None and '@' is in msg.text)
中删除 is
作为 :
@bot.message_handler(func=lambda msg: msg.text is not None and '@' in msg.text)
解释:
要检查该字符是否在文本中,只需使用 in
编写电报机器人。这里的代码:
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`
如何解决?请帮忙!
从行 @bot.message_handler(func=lambda msg: msg.text is not None and '@' is in msg.text)
中删除 is
作为 :
@bot.message_handler(func=lambda msg: msg.text is not None and '@' in msg.text)
解释:
要检查该字符是否在文本中,只需使用 in