首页 > 解决方案 > 回溯,当我更改电报机器人上的令牌时,它可以工作,但在它给出错误之前

问题描述

这是一段代码

#token and set proxy
token = 'token'
bot = telebot.TeleBot(token, threaded= False)
apihelper.proxy = {'https':'socks5://'}

@bot.message_handler(commands=('start'))
def start_message(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    Showcase = types.KeyboardButton('---')
    Vakancy = types.KeyboardButton('---')
    City = types.KeyboardButton('---')
    Account = types.KeyboardButton('---')
    markup.add(Showcase,Vakancy)
    markup.add(City)
    markup.add(Account)
    bot.send_message(message.chat.id,'Приветсвую тебя'),reply_markup=markup)


if __name__ == "__main__":
    bot.polling()

如果我更改令牌一切正常,但对我来说,它不起作用,令牌不完全正确。我不知道发生了什么,因为我添加了最后一个按钮,它停止工作以免做

错误

Traceback (most recent call last):
  File "c:\Users\admin\Desktop\My Projects\Python\Shop bot\main.py", line 31, in <module>
    bot.polling()
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 394, in polling
    self.__non_threaded_polling(none_stop, interval, timeout)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 445, in __non_threaded_polling
    self.__retrieve_updates(timeout)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 280, in __retrieve_updates
    self.process_new_updates(updates)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 317, in process_new_updates
    self.process_new_messages(new_messages)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 339, in process_new_messages
    self._notify_command_handlers(self.message_handlers, new_messages)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1801, in _notify_command_handlers
    if self._test_message_handler(message_handler, message):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1769, in _test_message_handler
    if not self._test_filter(filter, filter_value, message):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1790, in _test_filter
    return test_cases.get(filter, lambda msg: False)(message)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1801, in _notify_command_handlers
    if self._test_message_handler(message_handler, message):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1769, in _test_message_handler
    if not self._test_filter(filter, filter_value, message):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1790, in _test_filter
    return test_cases.get(filter, lambda msg: False)(message)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1786, in <lambda>
    'commands': lambda msg: msg.content_type == 'text' and util.extract_command(msg.text) in filter_value,
TypeError: 'in <string>' requires string as left operand, not NoneType

标签: pythontelegramtelegram-bottraceback

解决方案


嗨兄弟这是阿卡什我发现了同样的错误现在得到了解决方案。

#token and set proxy
token = 'token'
bot = telebot.TeleBot(token, threaded= False)
apihelper.proxy = {'https':'socks5://'}

@bot.message_handler(commands=['start'])
def start_message(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    Showcase = types.KeyboardButton('---')
    Vakancy = types.KeyboardButton('---')
    City = types.KeyboardButton('---')
    Account = types.KeyboardButton('---')
    markup.add(Showcase,Vakancy)
    markup.add(City)
    markup.add(Account)
    bot.send_message(message.chat.id,'Приветсвую тебя',reply_markup=markup)


if __name__ == "__main__":
    bot.polling()

你可以看到我做了什么改变..


推荐阅读