Код
class BOT(object): token = config.token admin = 'admin' def __init__(self): self.bot = twx.botapi.TelegramBot(self.token) self.bot.get_me() last_updates = self.bot.get_updates(offset=0).wait() try: self.last_update_id = list(last_updates)[-1].update_id except IndexError: self.last_update_id = None print('last update id: {0}'.format(self.last_update_id)) def process_message(self, message,user): text = message.message.text chat = message.message.chat chat_id = message.message.chat.id chat_username = message.message.chat.username date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(message.message.date)) text = text.strip() user_file = '' user_file += str(user.id) to_logs = str(date) +':Got message: from chat: {1} username:{2}'.format(text,chat_id,chat_username) + """:'{0}'""".format(text) print(to_logs) with open('log\log.txt','a') as f_obj: f_obj.write(to_logs + '\n') bot_message = twx.botapi.send_message(chat_id,"Привет пользователь!") print(bot_message) def run(self): print('Main loop started') while True: updates = self.bot.get_updates(offset=self.last_update_id).wait() try: for update in updates: if int(update.update_id) > int(self.last_update_id): self.last_update_id = update.update_id self.process_message(update,twx.botapi.User) except Exception as ex: print(traceback.format_exc()) if __name__ == '__main__': try: BOT().run() except KeyboardInterrupt: print('Exiting...')
File “C:\Program Files\Python36\lib\site-packages\twx\botapi\botapi.py”, line 1933, in send_message
return TelegramBotRPCRequest('sendMessage', params=params, on_result=Message.from_result, **kwargs)
TypeError: __init__() missing 1 required positional argument: ‘token’