【发布时间】:2021-03-22 02:44:29
【问题描述】:
我正在使用 python-telegram-bot 库编写 Telegram 机器人。
当发布新的 YoutubeChannel 时,机器人应该向用户发送消息。
我创建了一个 telegram_bot.py,在其中创建了一个 TelegramBot 类。
在这个类中,我有这个功能:
telegram_bot.py
def __init__(self):
self.updater = Updater(token=telegram_token, use_context=True)
self.dispatcher = self.updater.dispatcher
self.updater.start_polling()
def send_message(self, text_message, context: CallbackContext):
context.bot.send_message(
chat_id="@<<my username>>", text=text_message)
在 main.py 中,我有一行代码应该使用上述函数发送消息,如下所示:
main.py
from telegram_bot import TelegramBot
tg_bot = TelegramBot()
tg_bot.send_message("New video!")
但是,当我运行上面的代码时,我得到了这个错误:
TypeError: send_message() 缺少 1 个必需的位置参数:'context'
但是在 send_message 定义中我已经定义了 context
【问题讨论】:
标签: python telegram python-telegram-bot