Hi friends i'm trying to apply decorator from another class on method in my class... it is my implementation of this Telegram API wrapper library : https://github.com/eternnoir/pyTelegramBotAPI
但在我的示例中,不是想从脚本中使用它,而是要像这样使用类方法:
class Bot:
def __init__(self, key):
self.key = key
self.bot=telebot.TeleBot(key)
def start(self):
self.bot.polling()
# Handle '/start' and '/help'
@self.bot.message_handler(commands=['help', 'start'])
def send_welcome(self,message):
self.bot.reply_to(message, """\
Hi there, I am EchoBot. \
I am here to echo your kind words back to you. \
Just say anything nice and I'll say the exact same thing to you!\
""")
# Handle all other messages with content_type 'text' (content_types defaults to ['text'])
@self.bot.message_handler(func=lambda message: True)
def echo_message(message):
self.bot.reply_to(message, message.text)
所有“自我”都被突出显示了……肯定不能正常工作-如果有人可以解释我做错了什么会很高兴? 尝试自定义的原始示例是:
import telebot
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
bot.reply_to(message, message.text)
bot.polling()