【问题标题】:Python bot (telebot) SyntaxErrorPython bot (telebot) SyntaxError
【发布时间】:2020-08-10 08:24:21
【问题描述】:

在创建自己的电报机器人时遇到错误

File "c:\Users\Кирилл\Desktop\python_bot — копия\main_part.py", line 7
bot.polling(none_stop=True, interval=0)
^
SyntaxError: invalid syntax

代码部分:

bot = TeleBot('ToKeN')
@bot.message_handler(content_types=['text'])
bot.polling(none_stop=True, interval=0)

【问题讨论】:

  • 能贴出完整的代码吗?

标签: python bots chatbot telegram-bot python-telegram-bot


【解决方案1】:

可能是@bot.message_handler(content_types=['text']) 中的@ 导致了错误。

删除 @ 并重试。

【讨论】:

    【解决方案2】:

    在@...之后你应该输入这样的方法:

    @bot.message_handler(commands=['hello'])
    def handler(message):
        bot.reply_to(message,'hello!'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2020-03-26
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 2020-01-09
      相关资源
      最近更新 更多